Abstract Factory: Distinguishing the Brand
Abstract Factory Players
These are the players that Abstract Factory brings to the stage:
- Consumer — The object that needs Products that work together.
- Products — The instances that are created and delivered to the Consumer by an Abstract Factory instance.
- Abstract Factory — The object that produces the Products.
The standard Abstract Factory
provides several Factory Methods
that return compatible Products.
All the Products returned by these methods are guaranteed to
work together. Think of these parts as part of the same Product Line
or Brand.Abstract Factory instances themselves are polymorphic.
By calling the Factory Methods
on a suitable Abstract Factory instance,
you can create a compatible set of parts.
A Trader takes Product Specification
and returns a compatible Product
A Trader is an Abstract Factory that exposes a single Factory Method.
While a traditional Abstract Factory determines what kind
of Product to create based upon which Factory Method is called, a Trader
makes this decision based upon its Specification argument.
All these Products are part of the same Product Line, naturally.The code below shows a and returns a compatible Product
PartFactoryTrader
whose
makeFactory(...)
method
returns a new PartFactory
object for the specified brand.
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |