I am a huge fan of software design principles such as SOLID and DRY. What other principles exist for OO software design?
Note. I’m not looking for answers like "comment your code" but instead looking for OO design principles like the ones discussed by Uncle Bob.
Chose composition over inheritance, is one.
Many people, especially those new to OO will start extending classes when all they really need to is to use composition. Really if you should ask your self, is the new class B a Class A? If not then you shouldn't extend.
For example, let's say I have a
Person
Class, aCar
Class, and I would like to make a new class called aDrivenCar
class. A naive implementation would be to say (let's pretend we got multiple inheritance)Is the DrivenCar a type of Person? No so it shouldn't be extending Person. Is the DrivenCar a Car? yes so it makes sense to extend
Using composition the implmentation would look like
A fairly comprehensive list from Wikipedia:
http://en.wikipedia.org/wiki/List_of_software_development_philosophies
KISS
Interface. Most design patterns are based on separation of interface & implementation.
YAGNI
When your API are expected to grow, use Abstract class instead of Interface. Adding a new method in Interface requires to change ALL the classes which implement it.