Category: Design Pattern

State Design Pattern

Introduction: Sometimes you want to build a class where its behavior changed according to its state. State Design pattern provides a good class structure to solve this issue. State Design pattern also known as Object for state pattern is used to represent the state of an object and the object behavior will changed according to Read More …

Command Design Pattern

Introduction: Command Design Pattern enables you to encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Example: The below code demonstrates the Command pattern to be used on a simple calculator. This caluclator doing unlimited number of undo’s & Redo’s . One Read More …

Iterator Design Pattern

Introduction: Sometimes you want to access a collection of objects in a sequential way without even expose how things is going inside your implementation . Iterator Design Pattern Provides you with a Skelton of how to design your classes to solve this issue. Example: static void Main(string[] args) { ListAggregate a = new ListAggregate(); a[0] Read More …

Mediator Design Pattern

Introduction: Sometimes you want to design your classes set that interact with each other in a loosely coupled manner by keeping your classes away from referring each other directly… Mediator Design Pattern solve this issue by promoting the idea of loosely coupling classes Example:   static void Main(string[] args) { CountryList countrylist = new CountryList(); Read More …

Interpreter Design Pattern

Introduction: Sometimes you want to define a grammar for special language for certain reasons. After defining the syntax of this language, you need to build an interpreter to interpret the language and do actions accordingly. Interpreter Design Pattern help you to define a well structure object oriented classed to parse your expressions against the new Read More …

Proxy Design Pattern

Introduction: Sometimes you become into a case where you does not or can not reference an object directly, but you still want to interact with that object to do some job. The intent of the proxy design pattern is to control access to an object by providing placeholder for it. Below example will make the Read More …

Flyweight Design Pattern

Introduction: Flyweight design pattern target to minimizes the memory usage by sharing as much data as possible with other similar objects. It is very useful when have large amount of objects in memory which have lot of similar values. by sharing the similar values between all the objects, memory usage will be much less. Example: Read More …

Composite Design Pattern

Introduction: Sometimes you want to treat a group of objects as a single instance. Composite design pattern is aiming to compose object into a structure of tree to represent part-whole hierarchy structures. A simple example of this design pattern is directory structure.. Each directory might contains some entries and those entries might be a directory. Read More …

Bridge Design Pattern

Introduction: Sometimes you want to decouple the abstraction from its implementation so both of them can be vary independently. Bridge design pattern helps you in implementing this decoupling easily. The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes Example:     static void Main() { // Create Record Set Read More …

Abstract Factory Design Pattern

Introduction: Sometimes you want to create an instance of class that is related to a family of classes without specifying the exact concert class. Factory design pattern came to solve this issue and make it easy for us. In order to avoid duplicating the code that make the decision everywhere an instance is created, we Read More …

Prototype Design Pattern

Introduction: Sometimes we have a case where we want to build an object based on another object instead of creating a new fresh object each time, we can make a copy of an already existing object instantly and start using the new created object. By doing so, we do not have to repeat the building Read More …

Singleton Design Pattern

Introduction: There is some cases when you want to have one and only one instance of a specific class and prevent anybody from having the ability to create more than one instance of that class. Singleton Design pattern came to solve this issue by defining a well known structure for your class   Example: Singleton Read More …

Adapter Design Pattern

Introduction: Sometimes you have set of classes with different interfaces and you want to call logic on those classes in a consistent way. Adapter design pattern solve this issue, by providing a technique (best practice)  to wrap those classes somehow to make it easy to deal with this set of classes. Also Adapter is responsible Read More …

Builder Design Pattern

Introduction: Sometimes you need to build your Classes in such away where its representation is different according to some attributes and this representation of this class needs to be separated from its construction. Builder Design pattern solve this issue by abstract complex object construction from its representation. Example: An example of Builder Design pattern is Read More …

Design Patterns

What is Design Pattern: Design Pattern: Is a general reusable solution to a commonly occurring problem in software. Design Patten is a description or template of how to solve the problem we usually face during software development life cycle. It is showing relationship between classes without specifying how the final application will looks like. It Read More …

Decorator Design Pattern

Introduction: Sometimes you want to add more responsibility to an object dynamically. Decorate Design Pattern provide us a flexible alternative to creating subclasses to extend this functionality. So you will not have to extend functionality by creating a child (Sub class) class. Example: class Program { static void Main() { Book b = new Book(); Read More …

Strategy Design Pattern

Introduction: Sometimes you want your object to behave differently if its internal status changed. The strategy Design pattern enables client code to choose which behavior from a family of behaviors and give client code a simple way to enable that behavior. Example:   interface ISortStrategy { string Sort(); } public string Sort() { return “0 Read More …