Define an interface for creating an object but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses
This means that an abstract Creator class defines an abstract create method (or provides a default create method) which returns an abstract Product. A ConcreteCreator class implements the abstract create method to return a ConcreteProduct. This enables the Creator to defer Product creation to a subclass. Factory Method is often used in the Abstract Factory pattern to implement the create methods
Pros.
� shields clients from concrete classes
� if a framework uses the Factory Method pattern, it enables third-party developers to plug-in new Products
� the Creator create method can be coded to return a default Product
Cons.
� coding a new Product means writing two classes � one for the concrete Product and one for the concrete Creator
� static � inheritance based
Provide an interface for creating families of related or dependent objects without specifying their concrete classes
This means that a �family� of abstract create methods (each of which returns a different AbstractProduct) are grouped in an AbstractFactory interface.
ConcreteFactory implementations implement the abstract create methods to
produce ConcreteProducts.
Pros.
� shields clients from concrete classes
� easy to switch product family at runtime � just change concrete factory
� �keep it in the family� � enforces product family grouping
Cons.
� adding a new product means changing factory interface + all concrete factories
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
The purpose of the Command pattern is to decouple an event generator (the Invoker) from the event handler (the Receiver). A ConcreteCommand class (sub-classed from Command) defines an execute () method which calls the appropriate method on the Receiver (the action method). The client is responsible for associating the Receiver with the Command and then the Command with an Invoker.
Pros.
� decouples Invoker from Receiver � makes Receiver more re-usable as it
doesn�t manage the relationship with the Invoker
� Command encapsulate a request � requests can be stored so they can be
undone, processed at a later time, etc.
� extensible � easy to add new Commands
� macros � commands can be grouped into macros so that multiple commands can
be run at once
� dynamic � e.g. different Commands, multiple Invokers, decide at runtime, etc.
Cons.
� can�t centralise related action methods in one Command class - only one method is used (execute ())
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
The implementations are much more alike than they are different.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Factory Method has one creation method, possibly among other methods. Abstract Factory has creation methods for a family of things and no other methods (in the example diagram).
The implementations are much more alike than they are different. Add a second creation method for a related thing to a Factory Method and you have an Abstract Factory. The diagrams in the book look nothing alike, but they could if you wanted them to.
Jigar Naik
Can i say AbstractFactory returns Factory and from that Factory we get the instance of concrete product ?
SCJP SCWCD AIX SOA AWS GA
The significant problems we face cannot be solved by the same level of thinking that created them -- Albert Einstein