What is difference between decorator and adapter, template and strategy, factory and abstract factory?

Decorator and Adapter.

Decorator Adaptar
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


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


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

 

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


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s