Sunday, March 16, 2008

Factory v/s Facade Design Pattern.

The Factory Pattern :

The factory completely abstracts the creation and initialization of the product from the client
This indirection enables the client to focus on its discrete role in the application without concerning itself with the details of how the product is created. Thus, as the product implementation changes over time, the client remains unchanged.


The Facade Pattern

Encapsulate the subsystem using a High-Level Interface/provides a
simplified and uniform interface to a large subsytem of classes.

The Client communicates with the 'Facade' which has methods to interact
with subsystems.The Client very rarely accesses objects in the subsystems.
Subsystems objects usually retain no knowledge of the client.
Subsystem objects do not normally maintain any reference to Faýade.


My Question is this:

Arent both these pattern quite similar becos both designs access an Interface
which inturn invokes the required object of the subsystems?

Can anyone explain the major difference?

1. the Factory Pattern, is very useful for the creation of
the objects which it then hands to you and you deal with
the objects directly.

The Facade pattern, tries to simplify things for you, as
it keeps the objects away from you. This simplifies your
life if you are dealing with several complex objects.

The Faýade pattern simplifies access to a related set of objects by providing one object that all objects outside the set use to communicate
with the set. This also promotes a weak coupling between the subsystem and its clients. This weak coupling allows you to vary the
components of the subsystem without affecting the clients.

Centralize the assembly of resources necessary to create an object. This prevents the need to change all classes from changing when a
Product changes and makes any change needed occur only in the Factory.


Unknown said...


Great post! Thanks you so much for the share. It is indeed a helpful one. I am looking forward of reading more article with the similar topic as this one. Good luck and More Power.

Façade India

Anonymous said...

Thanks maan, nice explanation.

Anonymous said...

nice explanation,Thanks