Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
Plab – Tirgul 12 Design Patterns
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
MVC Fall 2005 OOPD John Anthony. Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structural Design Patterns
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 5150 Software Engineering Lecture 16 Program Design 3.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Intro To MVC Architecture.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Software Architecture and Design BITS C461/IS C341 Software Engineering First Semester Aditya P. Mathur Department of Computer Science Purdue.
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Abstract Factory Pattern
Software Design Patterns
MPCS – Advanced java Programming
Factory Patterns 1.
Observer Design Pattern
Design Patterns with C# (and Food!)
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Model-View-Controller Design Pattern
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Structural Patterns
Model-View-Controller
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Presented by Igor Ivković
Presentation transcript:

Design Pattern

Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations.

History: Elements of Reusable Object-Oriented Software was published in 1994 by the so-called "Gang of Four" (Gamma et al.), which is frequently abbreviated as "GOF". That same year, the first Pattern Languages of Programming Conference was held and the following year, the Portland Pattern Repository was set up for documentation of design patterns.

Elements: Pattern name: increases vocabulary of designers Problem: intent, context, when to apply Solution: UML-like structure, abstract code Consequences: results and tradeoffs 4

5 Design Patterns Generally at a “higher level” of abstraction. Not about designs such as linked lists or hash tables. Generally descriptions of communicating objects and classes.

Types: Creational patterns: Deal with initializing and configuring classes and objects Structural patterns: Deal with decoupling interface and implementation of classes and objects Composition of classes or objects Behavioral patterns: Deal with dynamic interactions among societies of classes and objects How they distribute responsibility

Singleton Used to ensure that a class has only one instance. For example, one printer spooler object, one file system, one window manager, etc. One may use a global variable to access an object but it does not prevent one from creating more than one instance. Instead the class itself is made responsible for keeping track of its instance. It can thus ensure that no more than one instance is created.

8 Singleton Structure Singleton static Instance() SingletonOp() GetSingletonData() static uniqueInstance singletonData return uniqueinstance

Singleton public class SingletonDemo { private static volatile SingletonDemo instance = null; private SingletonDemo() { } public static SingletonDemo getInstance() { if (instance == null) { synchronized (SingletonDemo.class){ if (instance == null) { instance = new SingletonDemo (); } return instance; }

10 Observer Pattern Need to separate presentational aspects with the data, i.e. separate views and data. Classes defining application data and presentation can be reused. Change in one view automatically reflected in other views. Also, change in the application data is reflected in all views Defines one-to-many dependency amongst objects so that when one object changes its state, all its dependents are notified

11 Observer Pattern A=10% B=40% C=30% D=20% Application data A B C D ADCB Relative Percentages Y X Z A B C D Change notification Requests, modifications

12 When to use the Observer Pattern? When an abstraction has two aspects: one dependent on the other. Encapsulating these aspects in separate objects allows one to vary and reuse them independently. When a change to one object requires changing others and the number of objects to be changed is not known. When an object should be able to notify others without knowing who they are. Avoid tight coupling between objects.

13 Observer Pattern: Consequences Abstract coupling between subject and observer. Subject has no knowledge of concrete observer classes. (What design principle is used?) Support for broadcast communication. A subject need not specify the receivers; all interested objects receive the notification. Unexpected updates: Observers need not be concerned about when then updates are to occur. They are not concerned about each other’s presence. In some cases this may lead to unwanted updates.

14 Facade Pattern: Problem Client Classes Subsystem classes Need to communicate with

15 Facade Pattern: Solution Client Classes Subsystem classes Facade

16 Facade Pattern: Why and What? Need to provide a simple interface to many, often small, classes. But not necessarily to ALL classes of the subsystem. Façade provides a simple default view good enough for most clients. Facade decouples a subsystem from its clients. Subsystems often get complex as they evolve. A façade can be a single entry point to each subsystem level. This allows layering.

17 Facade Pattern: Participants and Communication Clients communicate with subsystem classes by sending requests to façade. Façade forwards requests to the appropriate subsystem classes. Clients do not have direct access to subsystem classes. Participants: Façade and subsystem classes

18 Facade Pattern: Benefits Promotes weak coupling between subsystem and its clients. Helps in layering the system. Helps eliminate circular dependencies. Shields clients from subsystem classes; reduces the number of objects that clients deal with.

19 Abstract Factory: The Problem 1.Consider a user interface toolkit to support multiple look- and-feel standards. 2.For portability an application must not hard code its widgets for one look and feel. How to design the application so that incorporating new look and feel requirements will be easy?

20 Abstract Factory Pattern: Solution 2.This class declares an interface to create different kinds of widgets. 1.Define an abstract WidgetFactory class. 3.There is one abstract class for each kind of widget and concrete subclasses implement widgets for different standards. 4.WidgetFactory offers an operation to return a new widget object for each abstract widget class. Clients call these operations to obtain instances of widgets without being aware of the concrete classes they use.

21 Abstract Factory: Solution WidgetFactory CreateScrollbar() CreateWindow() WindowScrollBar WWidgetFactory MacWidgetFactory Client WWindowMacWindow MacScrollBarWScrollBar One for each standard.

22 Abstract Factory Pattern: Participants and Communication AbstractFactory: Declares the interface for operations to create abstract product objects. ConcreteFactory: Implements the operations to create concrete product objects. AbstractProduct: Declares an interface for a type of product object. ConcreteProduct: Defines a product object to be created by the corresponding factory. Client: Uses only the interface declared by the abstractFactory and AbstractProduct classes.

Adapter Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Wrap an existing class with a new interface. Impedance match an old component to a new system

Problem An "off the shelf" component offers compelling functionality that you would like to reuse, but its "view of the world" is not compatible with the philosophy and architecture of the system currently being developed.

Model-View-Controller Model : The core of the application. This maintains the state and data that the application represents. When significant changes occur in the model, it notifies all of its views Controller : The user interface presented to the user to manipulate the application. View : The user interface which displays information about the model to the user. Any object that needs information about the model needs to be a registered view with the model.

28 The Model Most programs are supposed to do work, not just be “another pretty face” but there are some exceptions useful programs existed long before GUIs The Model is the part that does the work--it models the actual problem being solved The Model should be independent of both the Controller and the View But it provides services (methods) for them to use Independence gives flexibility, robustness

29 The Controller The Controller decides what the model is to do Often, the user is put in control by means of a GUI in this case, the GUI and the Controller are often the same The Controller and the Model can almost always be separated (what to do versus how to do it) The design of the Controller depends on the Model The Model should not depend on the Controller

30 The View Typically, the user has to be able to see, or view, what the program is doing The View shows what the Model is doing The View is a passive observer; it should not affect the model The Model should be independent of the View, but (but it can provide access methods) The View should not display what the Controller thinks is happening

31 Combining Controller and View Sometimes the Controller and View are combined, especially in small programs Combining the Controller and View is appropriate if they are very interdependent The Model should still be independent Never mix Model code with GUI code!

32 Separation of concerns As always, you want code independence The Model should not be contaminated with control code or display code The View should represent the Model as it really is, not some remembered status The Controller should talk to the Model and View, not manipulate them The Controller can set variables that the Model and View can read

The End ?