6. Iterator - Intent
Provide a way to access the elements of an
aggregate object sequentially without exposing its
underlying representation
毋須知曉聚合物件的內部細節,即可依序存取內含的
每⼀一個元素
A.K.A: Cursor
6
7. Iterator
• Accessing inner elements without exposing internal
structure
• Extract accessing and traversal responsibility to
Iterator
7
16. Template Method - Intent
Define the skeleton of an algorithm in an operation,
deferring some steps to subclasses. Template
Method lets subclasses redefine certain steps of an
algorithm without changing the algorithm’s structure
定義演算法的輪輪廓,某些步驟留留給⼦子類別填補,以便便
在不改變演算法整體構造的情況下讓⼦子類別去精煉某
些步驟
16
19. 1. Implement TemplateMehtod, define skeleton of an algorithm
2. define abstract primitive operations
implement the primitive operations
20. Template Method
• implement invariant once, leave the variant to
subclass to implement
• Extract common behavior to avoid duplication
(refactor to generalize)
• Program by difference
• Hook Operation
20