Design Patterns Pepper. Find Patterns Gang of Four created 23 Siemens published another good set x

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Chapter 7 – Design and Implementation
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Winter 2007ACS-3913 Ron McFadyen1 Also known as publish/subscribe The essence of this pattern is that one or more objects (called observers or listeners)
Software Engineering 2003 Jyrki Nummenmaa 1 OBJECT ARCHITECTURE DESIGN These slides continue with our example application, based on the simplified.
 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.
Figures – Chapter 7.
Lecture 10: Chapter 12 Pattern-Based Design
Chapter 7 – Design and Implementation Lecture 1 1Chapter 7 Design and implementation.
Chapter 7 – Object-Oriented Design
Chapter 7 – Design and Implementation Lecture 1 1Chapter 7 Design and implementation.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Spring 2010ACS-3913 Ron McFadyen1 Weather Station Page 39+ In this application, weather station devices supply data to a weather data object. As the data.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
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,
Observer Pattern Tu Nguyen. General Purpose When one object changes state, all the dependent objects are notified and updated. Allows for consistency.
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.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Winter 2007ACS-3913 Ron McFadyen1 Observer Pattern Problem: There are many objects (observers / subscribers) needing to know of the state changes, or events,
Building software from reusable components.
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ć
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns. What is wrong with this picture? Ball double gravity 32.1 Private: Enemy double gravity 32.1 Private: Don’t repeat yourself!
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 18 Slide 1 Software Reuse.
Software Engineering Muhammad Fahad Khan
Software Reuse Prof. Ian Sommerville
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 14Slide 1 Design with Reuse l Building software from reusable components.
Design Patterns.
Software Engineering Lecture 8 – Design and Implementation
Chapter 7 – Design and Implementation Lecture 2 1Chapter 7 Design and implementation.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
Programming in C# Observer Design Pattern
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 14Slide 1 Chapter 14 Design with Reuse.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 18 Slide 1 Software Reuse.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Chapter 7 – Design and Implementation 1Chapter 7 Design and implementation.
Chapter 7 – Design and Implementation Lecture 1 1Chapter 7 Design and implementation.
Software Reuse. Objectives l To explain the benefits of software reuse and some reuse problems l To discuss several different ways to implement software.
EKT 421 SOFTWARE ENGINEERING
Chapter 5 – Design and Implementation
Chapter 7 – Object-Oriented Design
Chapter 10 Design Patterns.
Chapter 7 – Design and Implementation
Observer Design Pattern
Chapter 7 – Design and Implementation
Presented by Igor Ivković
Chapter 7 – Design and Implementation
Object Oriented Design Patterns - Creational Patterns
Chapter 7 – Design and Implementation
Presented by Igor Ivković
Presentation transcript:

Design Patterns Pepper

Find Patterns Gang of Four created 23 Siemens published another good set x x Just Singleton pattern: pattern.html pattern.html

Singleton When there should only be one shared instance in a system - global variable – Ensure that only one instance of a class is created. – Provide a global point of access to the object.

Code Guide Create the class Use the class Singleton.getInstance().doSomething();

More Efficient If we see that the singleton object is already created we just have to return it without using any synchronized block.

How can your project use this? Log file class Audit file class

Design patterns  A design pattern is a way of reusing abstract knowledge about a problem and its solution.  A pattern is a description of the problem and the essence of its solution.  It should be sufficiently abstract to be reused in different settings.  Pattern descriptions usually make use of object-oriented characteristics such as inheritance and polymorphism. 7Chapter 7 Design and implementation

Pattern elements  Name  A meaningful pattern identifier.  Problem description.  Solution description.  Not a concrete design but a template for a design solution that can be instantiated in different ways.  Consequences  The results and trade-offs of applying the pattern. 8Chapter 7 Design and implementation

The Observer pattern  Name  Observer.  Description  Separates the display of object state from the object itself.  Problem description  Used when multiple displays of state are needed.  Solution description  See slide with UML description.  Consequences  Optimisations to enhance display performance are impractical. 9Chapter 7 Design and implementation

The Observer pattern (1) Pattern name Observer DescriptionSeparates the display of the state of an object from the object itself and allows alternative displays to be provided. When the object state changes, all displays are automatically notified and updated to reflect the change. Problem description In many situations, you have to provide multiple displays of state information, such as a graphical display and a tabular display. Not all of these may be known when the information is specified. All alternative presentations should support interaction and, when the state is changed, all displays must be updated. This pattern may be used in all situations where more than one display format for state information is required and where it is not necessary for the object that maintains the state information to know about the specific display formats used. 10Chapter 7 Design and implementation

The Observer pattern (2) Pattern nameObserver Solution description This involves two abstract objects, Subject and Observer, and two concrete objects, ConcreteSubject and ConcreteObject, which inherit the attributes of the related abstract objects. The abstract objects include general operations that are applicable in all situations. The state to be displayed is maintained in ConcreteSubject, which inherits operations from Subject allowing it to add and remove Observers (each observer corresponds to a display) and to issue a notification when the state has changed. The ConcreteObserver maintains a copy of the state of ConcreteSubject and implements the Update() interface of Observer that allows these copies to be kept in step. The ConcreteObserver automatically displays the state and reflects changes whenever the state is updated. ConsequencesThe subject only knows the abstract Observer and does not know details of the concrete class. Therefore there is minimal coupling between these objects. Because of this lack of knowledge, optimizations that enhance display performance are impractical. Changes to the subject may cause a set of linked updates to observers to be generated, some of which may not be necessary. 11Chapter 7 Design and implementation

Multiple displays using the Observer pattern 12Chapter 7 Design and implementation

A UML model of the Observer pattern 13Chapter 7 Design and implementation

Good Examples of Use Very Simple use example: pattern-java-example.html pattern-java-example.html MVC example: java/observer-and-observable.html Example using listener: Good description:

Design problems  To use patterns in your design, you need to recognize that any design problem you are facing may have an associated pattern that can be applied.  Tell several objects that the state of some other object has changed (Observer pattern).  Tidy up the interfaces to a number of related objects that have often been developed incrementally (Façade pattern).  Provide a standard way of accessing the elements in a collection, irrespective of how that collection is implemented (Iterator pattern).  Allow for the possibility of extending the functionality of an existing class at run-time (Decorator pattern). 15Chapter 7 Design and implementation