5. Abstract Factory - Intent
Provide an interface for creating families of related or
dependent objects without specifying their concrete
classes.
以同⼀一個介⾯面來來建立⼀一整族相關或相依的物件,不需
點明個物件真正所屬的具象類別
A.K.A: Kit
5
6. Abstract Factory
• system should be independent of how its products are
created, composed, and represented.
• system should be configured with one of multiple
families of products.
• reveal just their interfaces, not their implementations.
6
7. interface : declares operations
that create abstract objects
implements the operations to
create concrete objects
interface of the products
objects created by Concrete Factory
implementation of AbstractProduct
8. Abstract Factory
• Isolate concrete class: hiding product class name,
not in client code
• Easy to exchange product family: change factory
only
• Consistency
• Singleton factory: one and only one
8
16. Builder - Intent
Separate the construction of a complex object from
its representation so that the same construction
process can create different representations
16
17. interface: create parts of a product
construct and assemble parts
retrieving product
using builder to construct
parts
18.
19. Builder
• Vary product’s internal representation: hide
representation and internal structure of product and
how the product get assembled
• Isolates codes for construction and representation: hide
implementation, easy to exchange
• One step -> step-by-step
19
20.
21.
22. Abstract Factory v.s Builder
• For constructing complex objects
• Family v.s step-by-step
22