Share
Embed
Introduction to Design Patterns
Motivating developers to learn about design patterns.
Zaki Shaheen
July 15, 2014
Transcript
23 slides
-
Agenda • What is “design”? • What is “pattern”? •
Motivation for design patterns • “The pattern language” • Brief intro to GoF Design Patterns • How to learn design patterns • Summary + QnA -
What is “design”? "I think there is a profound and
enduring beauty in simplicity; in clarity, in efficiency. True simplicity is derived from so much more than just the absence of clutter and ornamentation. It's about bringing order to complexity." - Sir Johnathan Ive, Apple SVP of Industrial design. -
"a specification of an object, manifested by an agent, intended
to accomplish goals, in a particular environment, using a set of primitive components, satisfying a set of requirements, subject to constraints;" “Form follows function” -
What is “pattern”? • recurrence of a phenomenon (activity, event,
problem, solution, situation) ◦ explicit recurrence (Bathing, city centers, wanting to write) ◦ implicit recurrence (relationships, building entrance, screw drivers?) -
Motivation for design patterns • Patterns are everywhere and so
is design • The Pattern language by Christopher Alexander (1977) • Art of War by Sun Tzu. (300-500 BC) -
“The pattern language” • 253 patterns for towns, buildings and
construction • Towns (Ring roads, web of shopping, network of learning, green streets, graveyards) • Buildings (south facing outdoors, indoor sunlight, fire place) • Construction (box columns, stair vault, floor surface, colors) -
"The street cafe provides a unique setting, special to cities:
a place where people can sit lazily, legitimately, be on view, and watch the world go by... Encourage local cafes to spring up in each neighborhood. Make them intimate places, with several rooms, open to a busy path, where people can sit with coffee or a drink and watch the world go by. Build the front of the cafe so that a set of tables stretch out of the cafe, right into the street." https://www.patternlanguage.com/labyrinth/apl-tour2.html -
(Brief) introduction to GoF • Software architecture patterns • “Design
Patterns: Elements of Reusable Object-Oriented Software” • Creational / Structural / Behavioral -
Creational Design Patterns • Singleton ◦ UIApplication, UIWindow, zend_controller_front •
Object pool ◦ Reusable cells in UITableView, photo controller, carousels -
Structural Design patterns • Composite ◦ The “V” in MVC.
◦ View hierarchy ◦ Could be your REST representation. • Adapter • Decorator • Flyweight -
Behavioral Patterns • Observer ◦ NSNotification System ◦ ServiceManager, EventManager
(in ZF2) ◦ Also called pub-sub • Chain of responsibility ◦ UIResponder chain • Command ◦ NSInvocation • Iterator ◦ Enumerators -
Quiz: Is MVC a design pattern? • Model • View
• Controller -
Other patterns • Enterprise Architecture Patterns ◦ Gateway ◦ Mapper
◦ Front Controller ◦ Active Record ◦ http://martinfowler.com/eaaCatalog/ • SOA Patterns (http://www.soapatterns.org) • Cloud Patterns ◦ Load balancing, clustering, naming, provisioning ◦ http://cloudpatterns.org -
• What about your own design patterns? • Service layer
pattern? • Viper Architecture? -
Tips on learning patterns • Requires deep, focused and abstract
thinking • No use without solid OOP principles and design thinking/practice • No use without learning UML • No use without experience of problems • Read the GoF book • Think abstractly, profoundly, retrospectively • Start with birds eye view • Learn creational, structural and behavioral in that order. • Don't restrict yourself to GoF Book • Don't restrict yourself to other people's patterns -
Key takeaways • Design is not art. • Patterns are
everywhere, requires deep abstract thinking to find them. • Design patterns give a vocabulary to tackle “design” problems. -
Resources • The web is full of information • http://sourcemaking.com/design-patterns-and-tips
• Several books, ask me if you are interested. -
Quiz • Identify a pattern • Argue about design •
Think of a design pattern