Wednesday, September 3, 2014

OO Design Principles

  1. Single responsibility: every object should have single responsibility. ( there should be never more than a single reason to change a class)
  2. Open/Closed Principle: software should be open for extension but closed for modification.
  3. Liskov Substitution Principle: states that sub types must be substitutable for their base types.
  4. Interface segregation principle:  clients should not be forced to depend on methods they do not use
  5. Dependency Inversion Principle:  High level modules should not depend on low level modules. Both should depend on abstractions.  Abstraction should not depend on details but details should depend on abstractions.
  6. Cohesion: within class strong cohesion
  7. Coupling: low coupling.
  8. Many small classes with distinct responsibilities result in more flexible design.
  9. Use small interfaces so you don't require classes to implement more than they need.
  10. Refactor large interfaces so they inherit smaller interfaces
  11. Don't Repeat Yourself principle: Every piece of knowledge must have single unambiguous representation in the system.
  12. Repetition in logic calls for abstraction and repetition in process calls for automation.
  13. Repetition breeds errors and waste.

An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class.

A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality.

No comments:

Post a Comment