Ch4. The FactoryPattern
Head First Design Patterns
2014/04/24
vicall@Qlync Inc.
1
2.
OO Principles -ch1~3
Encapsulate what varies.
Favor composition(合成) over inheritance(繼承)
Program to interface, not implementations.
Strive for loosely coupled designs between objects
that interact.
Classes should be open for extension but closed for
modification.
2
The Factory MethodPattern defines an interface for creating
an object, but lets subclasses decide which class to instantiate.
Factory Method lets a class defer instantiation to subclasses.
10
–Ch4. The FactoryPattern
[ Dependency Inversion Principle ]
顛覆依賴守則
!
“Depend upon abstractions. Do not depend upon
concrete classes.”
依賴抽象類別,不要依賴具象類別。
12
OO Principles -ch1~4
Encapsulate what varies.
Favor composition(合成) over inheritance(繼承)
Program to interface, not implementations.
Strive for loosely coupled designs between objects that interact.
Classes should be open for extension but closed for modification.
Depend upon abstractions. Do not depend upon concrete
classes.
20