Design Patterns
Lets say our application uses a component A and now we want to replace A with a component from 3rd party , say it as B.
Since the component B is not in our control which means we dont have control on its interface as well. But the problem here is that our client code is already using interface A and we dont want it to change. How can existing and unrelated classes work in an application that expects classes with a different and incompatible interface? This is the problem we will be going to res
Today I will give you an overview of Data Transfer Objects (DTO). We will discuss what are they and how are they used and where.
DTO as defined by Martin is "An object that carries data between processes in order to reduce the number of method calls"
Lets read more on this .....
COR
Objective
To provide the appropriate handler present in the chain of handlers which can handle the incoming request.
Advantages
Loose coupling. This is based on "Data-Driven" concept.
Distribution of responsibilities
An aggregate object should give a way to access its elements without exposing its internal structure. There may be different ways to iterate through different elements. It is not advisable to flood your aggregate object with so many iterating mechanisms.
"Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation" .... Read more
Sometimes it's necessary to record the internal state of an object. This is required when implementing checkpoints and undo mechanisms that let users back out of tentative operations or recover from errors. You must save state information somewhere so that you can restore objects to their previous states.
Memento lets u do this , read more for examples
This pattern is also called as Virtual Constructor
Frameworks use abstract classes to define and maintain relationships between objects. A framework is often responsible for creating these objects as well.
Since Framework in not aware of applications for which it will be used, hence it is not aware of the sub classes of abstract classes it provides and therefore it delegates the responsibility of creating the instances of application specific class to the sub classes.....
Observer Pattern define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Dependent Objects are termed as Observers.
New Observers can easily be hooked in an existing list of Observers.
This article explains Observer pattern with example in Java. Read more for details
Singleton pattern is one of the most used design patterns in any system. The pattern states that
"Ensure a class only has one instance, and provide a global point of access to it."
Although it is simple to implement this pattern, I have explained the pattern with a real world example and diagrams. Read more for details
In this article I will discuss about one of the Structural pattern in GoF series which is composite pattern.
Composite pattern defines class hierarchies consisting of primitive objects and composite objects. Primitive objects can be composed into more complex objects, which in turn can be composed, and so on recursively.
It makes the client simple. Clients can treat composite structures and individual objects uniformly. Read more for examples and diagrams
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Sometimes we want to add responsibilities to individual objects, not to an entire class.One way to add responsibilities is with inheritance. Inheritence will cause all the objects of that derived class to change.
A more flexible approach is to enclose the component in another object that adds the border. The enclosing object is c
This article is part of our series of design patterns. The definition of Template pattern states that
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
The article demonstrates the pattern with UML diagrams and a C# code example
MVC stands for Model View Controller Pattern
This pattern is extensively used while architecting an enterprise J2EE applications.
When to use Strategy Pattern
When we have multiple implementations(algorithms)
When we follow composition relationship(has-a) in place of the inheritance relationship(is-a relationship)
When we have a variety of behaviors but these are not applicable to all the objects