Friday, December 6, 2013

Design and development principles

Encapsulate what varies – when a logic is encapsulated in one class, when this logic is going to be changed, only this class is affected. The client class would not be affected. Factory design pattern is one example of this principle, which encapsulate object creation code and provides flexibility to introduce new product later with no impact on existing code.
Favor composition over inheritance – Composition allows to change behaviour of a class at runtime by setting property that is using interface polymorphism, while Inheritance adds functionality at compile time. Composition is also know as HAS-A relation and inheritance is also known as IS-A relation. The design pattern Strategy, Decorator use this principle.
Programming for interface not implementation -
Loose coupling -
Hollywood principle -
DRY – don’t repeat yourself means don’t duplicated code.  e.g. util static method, constant
KISS - Keep It Simple and Stupid
YAGNI - You aren't gonna need it. Always implement things when you actually need them, never when you just foresee that you need them. see here

No comments:

Post a Comment