Saturday, 18 February 2017

Object-Oriented Design Principles


When we design our classes we need to keep some basic principle to make our class more robust and futuristic. Whenever we create our class we focused on loose coupling and high cohesion.
As per OO concept classes should be design some standard principle which are called as SOLID principle.

Type of OO design principle:

1.      Single Responsibility Principle
2.      Open Closed Principle
3.      Liskov's Substitution Principle
4.      Interface Segregation Principle
5.      Dependency Inversion Principle

Single Responsibility Principle
One class should have one and only one responsibility

Open Closed Principle
Software components should be open for extension, but closed for modification

Liskov's Substitution Principle
Derived types must be completely substitutable for their base types

Interface Segregation Principle
Clients should not be forced to implement unnecessary methods which they will not use

Dependency Inversion Principle
Depend on abstractions, not on concretions


Type of OO design Pattern:

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.


Creational Design Patterns
1)      Factory Pattern
In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.
2)      Abstract Factory Pattern
In Abstract Factory pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.
3)      Singleton Pattern
This pattern involves a single class which is responsible to create an object while making sure that only single object gets created
4)      Builder Pattern
A Builder class builds the final object step by step. This builder is independent of other objects
5)      Prototype Pattern
Prototype pattern refers to creating duplicate object while keeping performance in mind


Structural Design Patterns
1)      Adapter Pattern
Adapter pattern works as a bridge between two incompatible interfaces
2)      Bridge Pattern
This pattern involves an interface which acts as a bridge which makes the functionality of concrete classes independent from interface implementer classes
3)      Composite Pattern
Composite pattern is used where we need to treat a group of objects in similar way as a single object. Composite pattern composes objects in term of a tree structure to represent part as well as whole hierarchy
4)      Decorator Pattern
Decorator pattern allows a user to add new functionality to an existing object without altering its structure
5)      Façade Pattern
Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system
6)      Flyweight Pattern
Flyweight pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance
7)      Proxy Pattern
In proxy pattern, a class represents functionality of another class.


Behavioral Design Patterns
1)      Chain of Responsibility Pattern
Chain of responsibility pattern creates a chain of receiver objects for a request.
2)      Command Pattern
Command pattern is a data driven design pattern
3)      Interpreter Pattern
Interpreter pattern provides a way to evaluate language grammar or expression
4)      Iterator Pattern
This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation.
5)      Mediator Pattern
Mediator pattern is used to reduce communication complexity between multiple objects or classes.
6)      Memento Pattern
Memento pattern is used to restore state of an object to a previous state
7)      Observer Pattern
Observer pattern is used when there is one-to-many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically
8)      State Pattern
In State pattern, we create objects which represent various states and a context object whose behavior varies as its state object changes.
9)      Strategy Pattern
In Strategy pattern, we create objects which represent various strategies and a context object whose behavior varies as per its strategy object.
10)  Template Pattern
In Template pattern, an abstract class exposes defined way(s)/template(s) to execute its methods. Its subclasses can override the method implementation as per need but the invocation is to be in the same way as defined by an abstract class.
11)  Visitor Pattern
In Visitor pattern, we use a visitor class which changes the executing algorithm of an element class. By this way, execution algorithm of element can vary as and when visitor varies



1 comment: