Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Design Patterns in Swift ch0 Introduction

75 views

Published on

a brief introduction about design patterns in Swift language

Published in: Software
  • Be the first to comment

  • Be the first to like this

Design Patterns in Swift ch0 Introduction

  1. 1. Design Patterns in Swift Ch 0 Introduction Sai Li @ Yowoo Tech. 2017/3/17
  2. 2. Agenda • Prologue • What is Pattern? • OOP Recap 2
  3. 3. • After OOP • Clean Code, OOP, Design Pattern, Refactor, Platform Framework, Test • Future interview 3 know nothing work
  4. 4. What is a Pattern?
  5. 5. Christopher Alexander (1936 - )
  6. 6. Each pattern is a three-part rule, which expresses a relation between a certain context, a problem, and a solution. Christopher Alexander (1979, p. 247)
  7. 7. Pattern is a solution to a problem in a context
  8. 8. • Context: A CEO of a company • Problem: tough competition among the 
 delivery services, all restaurants were closed by other company. How to make users order other food? • Solution: 8 + 9 = 17
  9. 9. Pattern is a solution to a recurring problem in a context
  10. 10. • Context: A CEO of a company • Problem: tough competition among the 
 delivery services. How to get more orders? • Solution: Binding card then ordering for free. Threaten to selling card information and shut down server.
  11. 11. Pattern is a proven solution to a recurring problem in a context
  12. 12. • Context: A CEO of a company • Problem: tough competition among the 
 delivery services. How to get more orders? • Solution: Send coupons, hold activities. Buy UberEATs, FoodPanda…
  13. 13. Pattern is a proven solution to a recurring problem in a 
 specific context
  14. 14. • Context: tough competition among the 
 delivery services. A CEO of a company with limited budget • Problem: How to get more orders? • Solution: Send coupons, hold activities …
  15. 15. Pattern is a proven solution 
 to a recurring problem 
 in a specific context
  16. 16. Each pattern describes a problem that occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. — Christopher Alexander 16
  17. 17. 17 • Name • Context • Problem • Solution • Force • Resulting Context Context Problem Elements of Pattern Solution(Form) Force
  18. 18. Why learn Design Patterns? • Common ground for communication • Not for excluding outsiders • • Reusable is so hard • Standing on the shoulders of giants - Issac Newton 18
  19. 19. 20 Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Gang of Four (GoF) 1994 ~
  20. 20. References 
 by Teddy Chen 21
  21. 21. • Purpose 1. Creational 2. Structural 3. Behavioral
 22 • Scope 1. Class: static 2. Object: dynamic

  22. 22. 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
  23. 23. How to learn Design Patterns? • Joshua Kerievsky : A Learning Guide to Design Patterns • One more time 24
  24. 24. message (request) method (operation) encapsulation signature (name, parameters, return type)
  25. 25. • Design: Abstraction • Flow & Algorithms: Strategy • State: State
  26. 26. • type: a specific interface Dynamic Binding Polymorphism
  27. 27. Program to an interface, 
 not an implementation • Clients remain unaware of the specific types or class • Clients only know about the abstract class defining the interface.
  28. 28. Inheritance vs. Composition • White box & Black Box • Compile time & Runtime 30
  29. 29. Favor object composition over class inheritance
  30. 30. Delegate 32
  31. 31. • Class composition • Class inheritance • Parameterized type (Generic, Template)
 Array<String>() Reuse
  32. 32. aggregation acquaintance
 (association, using) has-A (part of) using (know of)
  33. 33. Toolkit vs. Framework
  34. 34. References • • https://s-media-cache-ak0.pinimg.com/736x/8d/dc/a5/8ddca508d43902192028cc0f0f1ad763.jpg • https://upload.wikimedia.org/wikipedia/en/b/bf/The_Timeless_Way_of_Building.jpg • https://d2hsbzg80yxel6.cloudfront.net/images/85778/original/9572054112.jpg • https://images-na.ssl-images-amazon.com/images/I/81r69ARQevL.jpg • https://d2hsbzg80yxel6.cloudfront.net/images/49583/original/9789866761799.jpg • https://images-na.ssl-images-amazon.com/images/I/41Uat %2B4bqAL._SX258_BO1,204,203,200_.jpg 36

×