Relations with Other Patterns Flashcards
What is the relation between Factory Method and Abstract Factory and Prototype?
Abstract Factory classes are often based on a set of Factory Methods, but you can also use Prototype to compose the methods on these classes.
What is the diffrence between Factory Method and Prototype?
You don’t need a class hierarchy to implement a prototype. You can have a working prototype right in the base class, so no inheritance is really necessary (if you don’t have subclasses). The factory method doesn’t really make sense without a class hierarchy
What is the relation between Factory Method and Iterator?
You can use Factory Method along with Iterator to let collection subclasses return different types of iterators that are compatible with the collections
What is the relation between factory Method and Template Method?
Factory Method is a specialization of Template Method. At the same time, a Factory Method may serve as a step in a large Template Method.
What is the diffrence between Abstarct Factory and Builder?
Builder focuses on constructing complex objects step by step. Abstract Factory specializes in creating families of related objects. Abstract Factory returns the product immediately, whereas Builder lets you run some additional construction steps before fetching the product.
Why Abstract Factory may be an alternative for Facade?
Abstract Factory can serve as an alternative to Facade when you only want to hide the way the subsystem objects are created from the client code.
How you can use Abstract Factory along with Bridge?
You can use Abstract Factory along with Bridge. This pairing is useful when some abstractions defined by Bridge can only work with specific implementations. In this case, Abstract Factory can encapsulate these relations and hide the complexity from the client code.
What is the relation between Abstarct Factory and Singleton?
Abstract Factories can all be implemented as Singletons.
What is the relation between Builder and Composite?
You can use Builder when creating complex Composite trees because you can program its construction steps to work recursively.
What is the relation between Builder and Bridge?
You can combine Builder with Bridge: the director class plays the role of the abstraction, while different builders act as implementations.
What is the relation between Builder and Singleton?
Builders can all be implemented as Singletons.
How Prototype can help working with Command pattern?
Prototype can help when you need to save copies of Commands into history
How Prototype can help with Composite and Decorator patterns?
Designs that make heavy use of Composite and Decorator can often benefit from using Prototype. Applying the pattern lets you clone complex structures instead of re-constructing them from scratch.
What is the relation between Prototype and Memento?
Sometimes Prototype can be a simpler alternative to Memento. This works if the object, the state of which you want to store in the history, is fairly straightforward and doesn’t have links to external resources, or the links are easy to re-establish
What is the relation between Facade and Singleton?
A Facade class can often be transformed into a Singleton since a single facade object is sufficient in most cases.
What is the diffrence between Singleton and Flyweight?
Flyweight would resemble Singleton if you somehow managed to reduce all shared states of the objects to just one flyweight object. But there are two fundamental differences between these patterns:
- There should be only one Singleton instance, whereas a Flyweight class can have multiple instances with different intrinsic states.
- The Singleton object can be mutable. Flyweight objects are immutable.