My Sites


Sunday, April 10, 2016

A Developer guide to design principles and patterns

A design pattern represents a set of guidelines which will help to avoid having a bad software design. The SOLID principle is the best examples for commonly used design principles. 

S - Single Responsibility Principle
O - Open/Closed Principle
L - Liskov Substitution Principle 
I - Interface Segregation Principle
D - Dependency Inversion Principle

Single Responsibility Principle - Classes/ Modules must have only one reason to change. High cohesion should be there, means class should has a single focus and single thing well done. And also a class should be loosely coupled.The single responsibility should be encapsulated by the class.Therefore strive for high cohesion and loosely coupled systems.

Open/Closed Principle - Classes/Modules should be open for extension and closed for modification. That means new behaviour can be added in future but it should not modify the existing source code and make it complex. This embrace to use or reply on abstractions/Interfaces.

Liskov Substitution Principle - Subtypes can be substitutable for their base types. It's about programming to super type. This allows us to use polymorphism in our application.

Interface Segregation Principle - Clients should not be depend on methods that they do not use. Use multiple small cohesive interfaces instead of one big fat interface. Again loosely coupled and high cohesion is embraced.

Dependency Inversion Principle - High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstraction should not depend on details/concrete. And details/concretes must depend on abstractions. Dependency Injection is based on Inversion of control. It is a design pattern which tells how one object knows about its other dependent object. Basically, it is about how components get hold in their dependencies.
Programming to interface not to the implementation.

A design pattern is a general reusable solution , which can be used to solve a problem in our application. It is kind of like a proven template.
Design patterns can be categorized to Creational, Structural, Behavioural, Concurrency and Architectural and etc.

Design pattern common usage
Designing Service Layers - Module Pattern
Overly Complicated Object Interfaces - Façade Pattern

Visibility Into State Changes / Messaging Middlewares - Observer Pattern

No comments:

Post a Comment