SlideShare a Scribd company logo
1 of 27
Download to read offline
Design Patterns
in Swift
Ch 4
Iterator
Template Method
Sai Li @ Yowoo Tech.
taipingeric@gmail.com
2017/6/9
Agenda
• Iterator
• Template Method
2
1. Factory Method
2. Strategy
3. Decorator
4. Composite
5. Iterator
6. Template Method
7. Abstract Factory
8. Builder
9. Singleton
10. Proxy
11. Adaptor
Kerievsky Joshua: A Learning Guide To Design Patterns
12. Bridge
13. Mediator
14. Observer
15. Chain of Responsibility
16. Memento
17. Command
18. Prototype
19. State
20. Visitor
21. Flyweight
22. Interpreter
23. Facade
Kerievsky Joshua: A Learning Guide To Design Patterns
purpose
creational structural behavioral
scope
class Factory Method Adaptor
Interpreter
Template Method
object
Abstract Factory
Builder
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Chain of Responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
Iterator
Iterator - Intent
Provide a way to access the elements of an
aggregate object sequentially without exposing its
underlying representation
毋須知曉聚合物件的內部細節,即可依序存取內含的
每⼀一個元素
A.K.A: Cursor
6
Iterator
• Accessing inner elements without exposing internal
structure
• Extract accessing and traversal responsibility to 

Iterator
7
accessing interface
1. accessing implementation
2. current index
create iterator
interface
create iterator
implementation
Swift Sequence
• for - in
• map
• reduce
• filter
• forEach
• …
12
Array
Dictionary
Set
1. Factory Method
2. Strategy
3. Decorator
4. Composite
5. Iterator
6. Template Method
7. Abstract Factory
8. Builder
9. Singleton
10. Proxy
11. Adaptor
Kerievsky Joshua: A Learning Guide To Design Patterns
12. Bridge
13. Mediator
14. Observer
15. Chain of Responsibility
16. Memento
17. Command
18. Prototype
19. State
20. Visitor
21. Flyweight
22. Interpreter
23. Facade
Kerievsky Joshua: A Learning Guide To Design Patterns
purpose
creational structural behavioral
scope
class Factory Method Adaptor
Interpreter
Template Method
object
Abstract Factory
Builder
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Chain of Responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
Template Method
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
Application
1. Implement TemplateMehtod, define skeleton of an algorithm
2. define abstract primitive operations
implement the primitive operations
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
Caller
Concrete Operation
Concrete Operation
Abstract Operation
Abstract Operation
Interface
Concrete Operation
Concrete Operation
Implementation
Hook Operation
22
Hook Operation
23
Hollywood Pattern: Don’t call me, I’ll call you
Template Method vs. Strategy
24
Inheritance
Delegate
Example in iOS
25
References
• 搞笑談軟⼯工
• Kerievsky Joshua: A Learning Guide To Design Patterns
• http://www.evilenglish.net/wp-content/uploads/2014/05/305908d1359615600-madejski-miracle-
wtf-shit_640_417_s_c1_center_top_0_0.jpg
27
Q & A

More Related Content

Similar to Design patterns in Swift Ch4: Iterator & Template Method

I gotta dependency on dependency injection
I gotta dependency on dependency injectionI gotta dependency on dependency injection
I gotta dependency on dependency injectionmhenroid
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptAnkitPangasa1
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptbryafaissal
 
King Tut Architecture
King Tut ArchitectureKing Tut Architecture
King Tut ArchitectureGary Pedretti
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 
ActionScript Design Patterns
ActionScript Design Patterns ActionScript Design Patterns
ActionScript Design Patterns Yoss Cohen
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsPaul Blundell
 
Structure mapping your way to better software
Structure mapping your way to better softwareStructure mapping your way to better software
Structure mapping your way to better softwarematthoneycutt
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"Agile Base Camp
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor PatternIder Zheng
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Steven Smith
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncubeMalisa Ncube
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentSVRTechnologies
 

Similar to Design patterns in Swift Ch4: Iterator & Template Method (20)

I gotta dependency on dependency injection
I gotta dependency on dependency injectionI gotta dependency on dependency injection
I gotta dependency on dependency injection
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
King Tut Architecture
King Tut ArchitectureKing Tut Architecture
King Tut Architecture
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
ActionScript Design Patterns
ActionScript Design Patterns ActionScript Design Patterns
ActionScript Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussions
 
Structure mapping your way to better software
Structure mapping your way to better softwareStructure mapping your way to better software
Structure mapping your way to better software
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"
 
Design pattern
Design patternDesign pattern
Design pattern
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor Pattern
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course Content
 

More from Chihyang Li

Image Style Transfer and AI on iOS Mobile App
Image Style Transfer and AI on iOS Mobile AppImage Style Transfer and AI on iOS Mobile App
Image Style Transfer and AI on iOS Mobile AppChihyang Li
 
Image style transfer and iOS CoreML, Vision Frameworks
Image style transfer and iOS CoreML, Vision FrameworksImage style transfer and iOS CoreML, Vision Frameworks
Image style transfer and iOS CoreML, Vision FrameworksChihyang Li
 
Machine Learning in Swift
Machine Learning in SwiftMachine Learning in Swift
Machine Learning in SwiftChihyang Li
 
Image style transfer & AI on App
Image style transfer & AI on AppImage style transfer & AI on App
Image style transfer & AI on AppChihyang Li
 
iOS Vision framework
iOS Vision frameworkiOS Vision framework
iOS Vision frameworkChihyang Li
 
Swift map & flatMap
Swift map & flatMapSwift map & flatMap
Swift map & flatMapChihyang Li
 
Swift Optional ??
Swift Optional ??Swift Optional ??
Swift Optional ??Chihyang Li
 
Scrum & Kanban Introduction
Scrum & Kanban IntroductionScrum & Kanban Introduction
Scrum & Kanban IntroductionChihyang Li
 
Design Patterns in Swift ch0 Introduction
Design Patterns in Swift ch0 IntroductionDesign Patterns in Swift ch0 Introduction
Design Patterns in Swift ch0 IntroductionChihyang Li
 
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISPObject Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISPChihyang Li
 
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSPObject Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSPChihyang Li
 
Object Oriented Programming in Swift Ch1 - Inheritance
Object Oriented Programming in Swift Ch1 - InheritanceObject Oriented Programming in Swift Ch1 - Inheritance
Object Oriented Programming in Swift Ch1 - InheritanceChihyang Li
 
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - EncapsulationObject Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - EncapsulationChihyang Li
 
Apple Swift API Design Guideline
Apple Swift API Design GuidelineApple Swift API Design Guideline
Apple Swift API Design GuidelineChihyang Li
 
DevOps 2016 summit
DevOps 2016 summitDevOps 2016 summit
DevOps 2016 summitChihyang Li
 
Slack introduction
Slack introductionSlack introduction
Slack introductionChihyang Li
 
Agile Development: Scrum introduction
Agile Development: Scrum introductionAgile Development: Scrum introduction
Agile Development: Scrum introductionChihyang Li
 

More from Chihyang Li (18)

Image Style Transfer and AI on iOS Mobile App
Image Style Transfer and AI on iOS Mobile AppImage Style Transfer and AI on iOS Mobile App
Image Style Transfer and AI on iOS Mobile App
 
Image style transfer and iOS CoreML, Vision Frameworks
Image style transfer and iOS CoreML, Vision FrameworksImage style transfer and iOS CoreML, Vision Frameworks
Image style transfer and iOS CoreML, Vision Frameworks
 
Machine Learning in Swift
Machine Learning in SwiftMachine Learning in Swift
Machine Learning in Swift
 
Image style transfer & AI on App
Image style transfer & AI on AppImage style transfer & AI on App
Image style transfer & AI on App
 
iOS Vision framework
iOS Vision frameworkiOS Vision framework
iOS Vision framework
 
Swift map & flatMap
Swift map & flatMapSwift map & flatMap
Swift map & flatMap
 
Swift Optional ??
Swift Optional ??Swift Optional ??
Swift Optional ??
 
Scrum & Kanban Introduction
Scrum & Kanban IntroductionScrum & Kanban Introduction
Scrum & Kanban Introduction
 
Design Patterns in Swift ch0 Introduction
Design Patterns in Swift ch0 IntroductionDesign Patterns in Swift ch0 Introduction
Design Patterns in Swift ch0 Introduction
 
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISPObject Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISP
 
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSPObject Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
 
Object Oriented Programming in Swift Ch1 - Inheritance
Object Oriented Programming in Swift Ch1 - InheritanceObject Oriented Programming in Swift Ch1 - Inheritance
Object Oriented Programming in Swift Ch1 - Inheritance
 
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - EncapsulationObject Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
 
Apple Swift API Design Guideline
Apple Swift API Design GuidelineApple Swift API Design Guideline
Apple Swift API Design Guideline
 
Swift capture
Swift captureSwift capture
Swift capture
 
DevOps 2016 summit
DevOps 2016 summitDevOps 2016 summit
DevOps 2016 summit
 
Slack introduction
Slack introductionSlack introduction
Slack introduction
 
Agile Development: Scrum introduction
Agile Development: Scrum introductionAgile Development: Scrum introduction
Agile Development: Scrum introduction
 

Recently uploaded

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Design patterns in Swift Ch4: Iterator & Template Method

  • 1. Design Patterns in Swift Ch 4 Iterator Template Method Sai Li @ Yowoo Tech. taipingeric@gmail.com 2017/6/9
  • 3. 1. Factory Method 2. Strategy 3. Decorator 4. Composite 5. Iterator 6. Template Method 7. Abstract Factory 8. Builder 9. Singleton 10. Proxy 11. Adaptor Kerievsky Joshua: A Learning Guide To Design Patterns 12. Bridge 13. Mediator 14. Observer 15. Chain of Responsibility 16. Memento 17. Command 18. Prototype 19. State 20. Visitor 21. Flyweight 22. Interpreter 23. Facade Kerievsky Joshua: A Learning Guide To Design Patterns
  • 4. purpose creational structural behavioral scope class Factory Method Adaptor Interpreter Template Method object Abstract Factory Builder Prototype Singleton Adapter Bridge Composite Decorator Facade Flyweight Proxy Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor
  • 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
  • 8.
  • 9. accessing interface 1. accessing implementation 2. current index create iterator interface create iterator implementation
  • 10.
  • 11.
  • 12. Swift Sequence • for - in • map • reduce • filter • forEach • … 12 Array Dictionary Set
  • 13. 1. Factory Method 2. Strategy 3. Decorator 4. Composite 5. Iterator 6. Template Method 7. Abstract Factory 8. Builder 9. Singleton 10. Proxy 11. Adaptor Kerievsky Joshua: A Learning Guide To Design Patterns 12. Bridge 13. Mediator 14. Observer 15. Chain of Responsibility 16. Memento 17. Command 18. Prototype 19. State 20. Visitor 21. Flyweight 22. Interpreter 23. Facade Kerievsky Joshua: A Learning Guide To Design Patterns
  • 14. purpose creational structural behavioral scope class Factory Method Adaptor Interpreter Template Method object Abstract Factory Builder Prototype Singleton Adapter Bridge Composite Decorator Facade Flyweight Proxy Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor
  • 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
  • 17.
  • 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
  • 21. Caller Concrete Operation Concrete Operation Abstract Operation Abstract Operation Interface Concrete Operation Concrete Operation Implementation
  • 23. Hook Operation 23 Hollywood Pattern: Don’t call me, I’ll call you
  • 24. Template Method vs. Strategy 24 Inheritance Delegate
  • 26.
  • 27. References • 搞笑談軟⼯工 • Kerievsky Joshua: A Learning Guide To Design Patterns • http://www.evilenglish.net/wp-content/uploads/2014/05/305908d1359615600-madejski-miracle- wtf-shit_640_417_s_c1_center_top_0_0.jpg 27 Q & A