What Are Design Patterns and Why Do I Need Them? Software professionals may be familiar with the term "Design Patterns," but many have no idea of where.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Design Patterns (Part 1) Design Patterns are time-tested solutions to recurring design problems. Are the answer to a question that commonly arises “How.
CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Plab – Tirgul 12 Design Patterns
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Design Patterns William A. Hoffman NYU OOP Class.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns Trends and Case Study John Hurst June 2005.
樣式導向設計 (Pattern-Oriented Design) 課程簡介 Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy:
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
Proxy.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
樣式導向設計 (Pattern-Oriented Design) 課程簡介
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns Introduction
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
DESIGN PATTERNS : Introduction
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Informatics 122 Software Design II
Presentation transcript:

What Are Design Patterns and Why Do I Need Them? Software professionals may be familiar with the term "Design Patterns," but many have no idea of where they come from and what they truly are. Consequently, some do not see the value and benefits design patterns bring to the software development process, especially in the areas of maintenance and code reuse. This talk will provide an introductory to design patterns from a historical perspective.

Is This A New Idea? Town planners and architects talk of design patterns all the time. Design patterns have their roots in the work of Christopher Alexander an architect. When talking about patterns in buildings and towns in 1977, he wrote “Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to the problem, in such a way that you can use this solution a million times over, without doing it the same way twice.” Christopher Alexander,

Shortly after, software professionals began to incorporate Alexander’s principle into the creation of early design pattern documentation as a guide to novice developers. Design patterns gained popularity in computer science after a certain book was published in 1994 by four authors, commonly know as Gang of Four or GOF

Gang of Four The GoF Book Gang of Four (GoF) Gamma, Helm, Johnson, Vlissides, - founders of movement. Gamma et al, Design Patterns: Elements of Reusable Object-Oriented Software, Addison Wesley, They offer advice and help for developing quality software An object-oriented design pattern systematically names, explains and evaluates an important and recurring design in object-oriented systems

Design Patterns Template TermDescription Pattern NameDescribes the essence of the pattern in a short, but expressive, name IntentDescribes what the pattern does Also Known AsList any synonyms for the pattern MotivationProvides an example of a problem and how the pattern solves that problem ApplicabilityLists the situations where the pattern is applicable StructureSet of diagrams of the classes and objects that depict the pattern ParticipantsDescribes the classes and objects that participate in the design pattern and their responsibilities CollaborationsDescribes how the participants collaborate to carry out their responsibilitiescollaborate ConsequencesDescribes the forces that exist with the pattern and the benefits, trade-offs, and the variable that is isolated by the pattern

Namemeaningful text that reflects the problem, e.g. Bridge, Mediator, Flyweight Problem addressedintent of the pattern, objectives achieved within certain constraints Contextcircumstances under which it can occur Forcesconstraints or issues that solution must address, forces may conflict! Solutionthe static and dynamic relationships among the pattern components. Structure, participants, collaboration. Solution must resolve all forces! Different authors use different templates to describe their patterns Information is not always presented in the same way. Consult your manual/source !!!

Types of Pattern There are 3 types of pattern … –Creational: Concerned with the process of object creation –Structural: Concerned with the composition of classes and objects –Behavioral: Concerned with the ways in which classes and objects interact and distribute the work

Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Adapter Bridge Composite Decorator Façade Flyweight Proxy Abstract Factory Builder Factory Prototype Singleton CreationalStructuralBehavioural Types of Design Patterns

Memento Intent Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later. Applicability – use Memento when: A snapshot of (some portion of) an object’s state must be saved so that it can be restored to that state later, and A direct interface to obtaining the state would expose implementation details and break the object’s encapsulation.

Memento

RectCaretaker Memento x,y Memento save() void restore(Memento) Rect x,y Memento save() void restore(Memento)

Proxy Intent Provide a surrogate or placeholder for another object to control access to it. Applicability You want a normally inaccessible or unavailable object to appear like an ordinary object. For example, the object might be: in a different process in a disk archive compressed not computed yet Forces Turning an object into a Proxy, or vice versa, should be transparent

Proxy

Additional Behaviour Leads to Different Types of Proxies A remote proxy provides a local representative for an object in a different address space. A virtual proxy creates expensive objects on demand. (lazy loading) A protection proxy controls access to the original object Protection proxies are useful when objects should have different access rights. A cache proxy caches the output of the Subject class. A Proxy can cache stable information about the subject to postpone accessing it. Some Proxy Flavours!

Cached Proxy Client CalculatorBase Calculate() NumberMultiplier Calculate() NumberMultiplierProxy Calculate()

Virtual Proxy Client Imager GetImage() ImageName QuickImage GetImage() ImageName ImageProxy GetImage() ImageName FinalImage GetImage() ImageName

Participants of Proxy pattern Proxy Maintains a reference that lets the proxy access the real object Provides an interface identical to the Subject’s so that a proxy can be substituted for the real subject. Controls access to the real subject and may be responsible for creating and deleting it. Other responsibilities depend on the kind of proxy

State Intent – Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. Applicability – use in either of the following cases: – An object’s behavior depends on its state, and it must change its behavior at run-time depending on that state. – Operations have large, multipart conditional statements which depends on the object’s state. This state is usually represented by one or more enumerated constants. Often, several operations will contain this same conditional structure. The State pattern puts each branch of the conditional in a separate class. This lets you treat the object’s state as an object in its own right that can vary independently from other objects.

State Design Pattern

State Invoice IStatus Issue() Pay() Cancel() PendingState Issue() Pay() Cancel() PaidState Issue() Pay() Cancel() CancelledState Issue() Pay() Cancel()

Summary Design patterns assist developers by: Providing templates for common problems Creating a common nomenclature Creating components that are more reusable and flexible The.NET Framework includes features that makes some of the patterns easier to implement.

For more Information Websites Microsoft patterns & practices Books Design patterns: Elements of Reusable Object Oriented Software (Addison-Wesley, 1995) Head First Design Patterns - O’Reilly Media