Posts

Factory Design Pattern

Image
A Factory Pattern or Factory Method Pattern says that just  define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate.  In other words, subclasses are responsible to create the instance of the class. Advantage of Factory Design Pattern Factory Method Pattern allows the sub-classes to choose the type of objects to create. It promotes the  loose-coupling  by eliminating the need to bind application-specific classes into the code. That means the code interacts solely with the resultant interface or abstract class, so that it will work with any classes that implement that interface or that extends that abstract class. Usage of Factory Design Pattern When a class doesn't know what sub-classes will be required to create When a class wants that its sub-classes specify the objects to be created. When the parent classes choose the creation of objects to its sub-classes. UML for Factory Method Pat...

Gang of Four Design Pattern

Creational Singleton Factory Abstract Factory Builder Prototype Structural Adapter Composite Proxy Fly Weight Façade Bridge Decorator Template method Mediator Chain of responsibility Observer Strategy Command State Visitor Iterator Interpreter Momento

Business Delegate

Image
Business Delegate  - A single entry point class for client entities to provide access to Business Service methods. LookUp Service  - Lookup service object is responsible to get relative business implementation and provide business object access to business delegate object. Business Service  - Business Service interface. Concrete classes implement this business service to provide actual business implementation logic. Implementation We are going to create a Client, BusinessDelegate, BusinessService, LookUpService, JMSService and EJBService representing various entities of Business Delegate patterns. BusinessDelegatePatternDemo, our demo class, will use BusinessDelegate and Client to demonstrate use of Business Delegate pattern. Step 1 Create BusinessService Interface. BusinessService.java public interface BusinessService { public void doProcessing (); } Step 2 Create concrete Service classes. EJBService.java public class EJBS...

Chain of Responsibilty

Image
Chain of responsibility pattern is used to achieve loose coupling in software design where a request from the client is passed to a chain of objects to process them. Later, the object in the chain will decide themselves who will be processing the request and whether the request is required to be sent to the next object in the chain or not. Where and When Chain of Responsibility pattern is applicable : When you want to decouple a request’s sender and receiver Multiple objects, determined at runtime, are candidates to handle a request When you don’t want to specify handlers explicitly in your code When you want to issue a request to one of several objects without specifying the receiver explicitly. This pattern is recommended when multiple objects can handle a request and the handler doesn’t have to be a specific object. Also, the handler is determined at runtime. Please note that a request not handled at all by any handler is a valid use case. Handler :  This ca...