Friday, July 25, 2008

OO Design Principles and Patterns

Principle 1: “Encapsulate what varies”


Identify the aspects of yours application that vary and separate them from what stays the same. This principle helps to make the future changes without affecting the code that doesn’t vary.





Principle 2: “Program to an Interface, not an Implementation”


This will decouple the class implementation from the class that uses them. So, the clients may not need to know the complete implementation.





Principle 3: “Favour Composition over Inheritance”


This principle lets you change behaviour at runtime.





Principle 4: “Strive for loosely coupled designs between objects that interact”


Loosely coupled designs allow us to build flexible OO systems that can handle change because they minimize the interdependency between objects.





Principle 5: “Classes should be open for extension, but closed for modification


Modifying existing code will always lead to introduce new bugs. Design your classes in such a way that they would be easily extended to incorporate new behaviour without modifying the existing code.





Principle 6: “Dependency Inversion Principle – Depend upon Abstractions. Do not depend upon Concrete classes”


This principle suggests that high-level components should not depend on our low-level components. Rather both should depend on abstractions.





Principle 7: “Principle of least knowledge – talk only to your immediate friends”


It means when you are designing a system, for any object, be careful of the number o f classes it interacts with and also how it comes to interact with those classes. This principle prevents us from creating designs that have a large number of classes coupled together so that changes in one part of the system cascade to other parts.





Principle 8: “A class should have only one reason to change”


This principle guides us to assign each responsibility to one class, and only one class.





Please get the details about various design patterns here

Read More......
 
Template design by Amanda @ Blogger Buster