Singleton
Ensures that only one object of a particular class is ever created. Real world example There can only be one president of a country at a time. The same president has to be brought to action, whenever duty calls. President here is singleton.
Prototype
Create object based on an existing object through cloning. Real world example Remember dolly? The sheep that was cloned! Lets not get into the details but the key point here is that it is all about cloning
Builder
Allows you to create different flavors of an object while avoiding constructor pollution. Useful when there could be several flavors of an object. Or when there are a lot of steps involved in creation of an object. Real world example Imagine you are at Hardee's and you order a specific deal, lets…
Abstract Factory
A factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes. Real world example Extending our door example from Simple Factory. Based on your needs you might get a wooden door from a wooden door shop, iron door from a…
Factory Method
It provides a way to delegate the instantiation logic to child classes. Real world example Consider the case of a hiring manager. It is impossible for one person to interview for each of the positions. Based on the job opening, she has to decide and delegate the interview steps to different people.
Simple Factory
Simple factory simply generates an instance for client without exposing any instantiation logic to the client Real world example Consider, you are building a house and you need doors. You can either put on your carpenter clothes, bring some wood, glue, nails and all the tools required to build the do…
Behavioral Design Patterns
It is concerned with assignment of responsibilities between the objects. What makes them different from structural patterns is they don't just specify the structure but also outline the patterns for message passing/communication between them. Or in other words, they assist in answering "Ho…
State
It lets you change the behavior of a class when the state changes. Real world example Imagine you are using some drawing application, you choose the paint brush to draw. Now the brush changes its behavior based on the selected color i.e. if you have chosen red color it will draw in red, if blue then …
Structural Design Patterns
Structural patterns are mostly concerned with object composition or in other words how the entities can use each other. Or yet another explanation would be, they help in answering "How to build a software component?" Types of Structural Patterns Adapter Bridge Composite Decorator Facade Flyweigh…
Creational Design Patterns
Creational patterns are focused towards how to instantiate an object or group of related objects. Types of Creational Patterns Simple Factory Factory Method Abstract Factory Builder Prototype Singleton
Design Patterns
A software design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used i…