Difference between decorator,adapter,template,strategy,factory,abstract factory?

1.6K 0 0
                                    

Decorator and Adapter.

Decorator

Used to deal with new behavior or responsibilities without affecting existing code Mainly involved in converting interfaces as per the requirement of client

Provides a wrapper over objects to apply same method which yields different results based on whether the object invoked is granular or composite Allows use of new libraries without changing existing methods

Change of interface does not happen Change of interface happens in this case

Adaptar

Mainly involved in converting interfaces as per the requirement of client

Allows use of new libraries without changing existing methods

Change of interface happens in this case

Template and Strategy.

Template Strategy Defines outline for algorithms and allows sub class to override some steps Uses object composition to provide variety of algorithm implementation

Efficient in terms of less redundant code Flexible in terms of allowing users to change algorithm at run time

Depends on super class for methods All the algorithms can be itself implemented

Strategy

Uses object composition to provide variety of algorithm implementation

Flexible in terms of allowing users to change algorithm at run time

All the algorithms can be itself implemented

Factory and Abstract Factory.

Factory Abstract factory Specifies creation method which will be  used by sub class for object creation Used to create group of related objects while hiding actual classes

Deals with single product Deals with number of products

Each concrete factory implements abstract factory in case more than one products needed to be supported Makes uses of factory pattern provided by each family of product

Abstract factory

Used to create group of related objects while hiding actual classes

Deals with number of products

Makes uses of factory pattern provided by each family of product

See the following JAVA / J2EE/ Core Java video on get started with Apache CXF.

http://www.youtube.com/watch?v=fRrBFguxL9Y

Also visit our site from more such Java / J2EE/ Core Java interview question with answers videos.

Difference between decorator,adapter,template,strategy,factory,abstract factory?Where stories live. Discover now