Information is taken from : [Journal Dev Java Design Pattern Example Tutorial] (http://www.journaldev.com/1827/java-design-patterns-example-tutorial)
#Creational Design Patterns ###Patterns to use when an object is being instantiated
-
Singleton Pattern : Used when we want only one instance of a class. Implement using a static inner class with a private final outer class object for confirmed single instance.
-
Factory Pattern : Used when parent class has many sub class and we want an object of those classes. Implement it using a factory class which uses if elseif code for returning sub class object based on some condition and cast it to parent class (Dynamic Run time overriding)
-
Abstract Factory Pattern : Usage same as factory to remove if checks. Implement it by making abstract factory class and then its impl of base class, and all subclasses. The base class abstract impl should accept values from sub class abstract impl.
-
Builder pattern : Used when object has too many parameters. Implement it by making an inner static class with same parameters as outer class and then set those parameters with some default values to them and on build() return outer class object parameters set to parameters initialized in inner static builder class object.
#Structural Design Patterns ###Patterns to use to provide code or class or project or feature structure
-
Adapter Pattern : Used when we have to combine two unrelated things. Implement by composition i.e. simply having the object in the class.
-
Composite Pattern : Used when same thing is to be applied all objects in a structure. Implement using a base interface.
-
Proxy Pattern : Used when we don't want to give full functionality of an object. Implement using a proxy object with access control or isAllowed variable.
-
Facade Pattern : Used to reduce object complexity. Implement by composition of unrelated objects in facade object and give a function to provide functionality.
-
Bridge Pattern : Used when two interfaces interact with each other. Implement by composition of base interface object in another interface's impl's. And then calling interface function to dynamically decide function to be called.
-
Decorator Pattern : Used when we have to modify functionality at runtime. Implement by composition of base interface class object in base decorator class extending base interface. Then make sub decorator classes.
#Behavioral Design Patterns ###Patterns which provides solutions for interaction between objects , loose coupling and flexibility
-
Template Method Pattern : Used when we have some template for subclasses. Implement using abstract classes.
-
Mediator Pattern : Used when there is tight coupling to be transformed into loose coupling. Implement by composition of an interface in both modules and an Impl of this interface having composition of one or both modules. Then interact using this impl.
-
Observer Pattern : Used when we are interested in state of an object and want to know if it changes. Implement by having registered listeners which update you on any change in state.
-
Strategy Pattern : Used when we have multiple ways to do a thing and the particular way is decided at runtime. Implement using interface and their implementations.
-
Command Pattern : Used when there is a request response model. Implement by making command and reciever interface and their Impl. The reciever impl will recieve a command object and then return a response object.
-
State Pattern : Used when an object behavior changes based on internal state. Implement by having a state interface and define its various state impl. Next have a impl object in main object and implement state again. On state action invokation pass the parameters to the local state variable action.
-
Visitor Pattern : Used when we have to perform a operation on similiar kind of objects whose implementation differ a bit for each object. Implement using base interface for similiar objects which takes another interface impl as object and calls a function there with this class object as parameter. In the other interface impl mentioned, implement or overload methods accepting similiar kind object classes as parameters and do the operation on each object there.