Design Patterns : Template Method

The purpose of a Template Method Pattern is to define the skelton of an algorithm, while deferring the exact steps to sub classes. There is plenty of literature on the internet detailing the pattern, so we will skip it and head right to the code. As always, lets begin by defining the contract interface, in … Continue reading Design Patterns : Template Method

Advertisements

Design Patterns : Chain of Responsibility

The intend of Chain of Responibility Pattern is to avoid coupling the sender of a request to its reciever by giving more than one object change to handle the request. Let's try to mimic the execution of classical Waterfall Model with CoR. Let's begin by declaring the contract interface. And our sub classes. The final … Continue reading Design Patterns : Chain of Responsibility

Design Patterns : Fascade Pattern

Fascade, name being an analogy to an architectural fascade, intends set the tone for the entire functionality by providing a simplified yet effective interface wrapping away the complex, pooly designed collection of APIs. Wrong Code Consider following set of Classes.   The Client Code could be As you can see, the Client class is invoking … Continue reading Design Patterns : Fascade Pattern

Patterns,Principles and Programming.

Have been thinking of building a complete index of all programming series available in this blog for some time now. So finally putting it together. Design Patterns 1. GOF: Adapter Pattern 2. GOF: Strategy Pattern 3. GOF: Singleton Pattern (Lazy) 4. GOF: Fascade Pattern 5. GOF: Chain Of Responsibility Pattern (CoR) 6. GOF: Template Method … Continue reading Patterns,Principles and Programming.

Design Patterns : Strategy Pattern

Strategy Pattern lets you create a family of strategies (algorithm) encapsulated into separate interchangeable classes. In our example, we will consider a Client class which needs to invoke different sorting algorithm.   Let's first create the contract interface for different Sorting algorithm. Now that we have our interface ready, let's go ahead and implement different … Continue reading Design Patterns : Strategy Pattern

Design Patterns : Adapter Pattern

There is already a large amount of literature on the Internet which discusses Adapter Pattern. However, the purpose of article is to showcase the implementations of the Adapter Pattern, rather than discussing the application of the pattern. In this post, adapter class is implemented using 1. Inheritance 2. Dependency Injection 3. Generics Consider your old … Continue reading Design Patterns : Adapter Pattern

SOLID : Open / Closed Principle

The Open / Closed Principle focuses on one basic requirement, the classes should be Open for extensions, but closed for modification. The better way to explain the principle would be to first express the issue in hand. Consider the below class. The class itself looks good, but what if in future one needs to add … Continue reading SOLID : Open / Closed Principle