CS 5150 1 CS 5150 Software Engineering Lecture 17 Object Oriented Design 3.

Slides:



Advertisements
Similar presentations
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
Advertisements

Chapter 8, Object Design: Design Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.
Plab – Tirgul 12 Design Patterns
CSE Software Engineering: Analysis and Design, 2005Lecture 8A.1 Software Engineering: Analysis and Design - CSE3308 Design and Analysis Patterns.
1 CS 501 Spring 2005 CS 501: Software Engineering Lecture 17 Object Oriented Design 3.
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
Chapter 8, Object Design Introduction to Design Patterns
1 CS 501 Spring 2008 CS 501: Software Engineering Lectures 17 & 18 Object Oriented Design 3 & 4.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
CS CS 5150 Software Engineering Lecture 16 Object Oriented Design 2.
CS CS 5150 Software Engineering Lecture 16 Object Oriented Design 2.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Reuse Activities Selecting Design Patterns and Components
1 CS 501 Spring 2007 CS 501: Software Engineering Lectures 17 & 18 Object Oriented Design 3 & 4.
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.
Chapter 8, Object Design: Design Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
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.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
CEN 4010 Ninth Lecture March 4, 2005 Introduction to Software Engineering (CEN-4010) Spring 2005 Instructor: Masoud Sadjadi
Proxy Pattern: Motivation
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Design Patterns ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
CS 5150 Software Engineering Lecture 16 Program Design 3.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
COP 3331 Object-Oriented Analysis and Design 1 Design Overview  Design Overview (Ch 6)  Review of RAD  System Design  System Design Concepts  System.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
CEN 5011 Sixth Lecture (2 nd part) Oct 20, 2004 Advance Software Engineering (CEN-5011) Fall 2004 Instructor: Masoud Sadjadi
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
Chapter 10 Design Patterns.
Factory Patterns 1.
Introduction to Design Patterns
Instructor: Dr. Hany H. Ammar
Design Patterns with C# (and Food!)
object oriented Principles of software design
Presented by Igor Ivković
Design Patterns - A few examples
UNIT-III Structural Design Patterns
Structural Patterns: Adapter and Bridge
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Presentation transcript:

CS CS 5150 Software Engineering Lecture 17 Object Oriented Design 3

CS Administration Quiz 3: Thursday March 26 Quiz 3 is on Thursday, March 26. Each quiz covers material from all the lectures, up to and including the previous class. Assignment 3: Presentation Sign up a time for your presentation. Time slots are on the web site. Weekly progress reports Remember to submit your reports on Friday

CS Design Patterns Sources: E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994 The following discussion of design patterns is based on Gamma, et al., 1994, and Bruegge and Dutoit, Wikipedia has good discussion of many design patterns using UML and other notation, with code samples (March 23, 2009).

CS Design Pattern Design patterns are template designs that can be used in a variety of systems. They are particularly appropriate in situations where classes are likely to be reused in a system that evolves over time. Name. [Some of the names used by Gamma, et al. have become standard software terminology.] Problem description. Describes when the pattern might be used, often in terms of modifiability and extensibility. Solution. Expressed in terms of classes and interfaces. Consequences. Trade-offs and alternatives.

CS Notation ClassNameclass name in italic indicates an abstract class dependency delegation inheritance whole/part association wholepart

CS Facade: Encapsulating Subsystems Name: Facade design pattern Problem description: Reduce coupling between a set of related classes and the rest of the system. Solution: A single Facade class implements a high-level interface for a subsystem by invoking the methods of the lower-level classes. Example. A Compiler is composed of several classes: LexicalAnalyzer, Parser, CodeGenerator, etc. A caller invokes only the Compiler (Facade) class, which invokes the contained classes.

CS Facade: Class Diagram Facade service() Class1 service1() Class2 service2() Class3 service3() Facade

CS Facade: Consequences Consequences: Shields a client from the low-level classes of a subsystem. Simplifies the use of a subsystem by providing higher-level methods. Enables lower-level classes to be restructured without changes to clients. Note. The repeated use of Facade patterns yields a layered system.

CS Adapter (Wrapper): Wrapping Around Legacy Code Problem description: Convert the interface of a legacy class into a different interface expected by the client, so that the client and the legacy class can work together without changes. This problem often occurs during a transitional period, when the long-term plan is to phase out the legacy system. Example: How do you use a web browser to access an information retrieval system that was designed for a different client?

CS Adapter Design Pattern: The Problem LegacyClass existingRequest() NewClient OldClient NewClass request() dependency

CS Adapter Design Pattern: Solution Class Diagram ClientInterface request() Adapter request() LegacyClass existingRequest() Client abstract class shown in italic delegation inheritance

CS Adapter Design Pattern: Consequences The following consequences apply whenever the Adapter design pattern in used. Client and LegacyClass work together without modification of either. Adapter works with LegacyClass and all of its subclasses. A new Adapter needs to be written if Client is replaced by a subclass.

CS Strategy: Encapsulating Algorithms Name: Strategy design pattern Problem description: Decouple a policy-deciding class from a set of mechanisms, so that different mechanisms can be changed transparently. Example: A mobile computer can be used with a wireless network, or connected to an Ethernet, with dynamic switching between networks based on location and network costs.

CS Strategy Example: Class Diagram for Mobile Computer NetworkInterface open() close() send() Application Ethernet open() close() send() WirelessNet open() close() send()

CS Strategy Example: Class Diagram for Mobile Computer NetworkConnection send() setNetworkInterface() NetworkInterface open() close() send() ApplicationLocationManager Ethernet open() close() send() WirelessNet open() close() send() use location information to select network

CS Strategy: Class Diagram Context contextInterface() Strategy algorithmInterface() Client ConcreteStrategy2 Policy ConcreteStrategy1 Policy class selects ConcreteStrategy

CS Strategy: Encapsulating Algorithms Solution: A Client accesses services provided by a Context. The Context services are realized using one of several mechanisms, as decided by a Policy object. The abstract class Strategy describes the interface that is common to all mechanisms that Context can use. Policy class creates a ConcreteStrategy object and configures Context to use it.

CS Strategy: Consequences Consequences: ConcreteStrategies can be substituted transparently from Context. Policy decides which Strategy is best, given the current circumstances. New policy algorithms can be added without modifying Context or Client.

CS Bridge: Allowing for Alternate Implementations Name: Bridge design pattern Problem description: Decouple an interface from an implementation so that a different implementation can be substituted, possibly at runtime (e.g., testing different implementations of the same interface).

CS Bridge: Class Diagram Client ConcreteImplementorA ConcreteImplementorB alternative implementations

CS Bridge: Class Diagram Implementor Client ConcreteImplementorA ConcreteImplementorB

CS Bridge: Class Diagram AbstractionImplementor Client ConcreteImplementorA ConcreteImplementorB whole/part association Note the similarity to the strategy design pattern

CS Bridge: Allowing for Alternate Implementations Solution: The Abstraction class defines the interface visible to the client. Implementor is an abstract class that defines the lower-level methods available to Abstraction. An Abstraction instance maintains a reference to its corresponding Implementor instance. Abstraction and Implementor can be refined independently.

CS Bridge: Class Diagram Abstraction RefinedAbstraction Implementor Client ConcreteImplementorA ConcreteImplementorB new abstraction

CS Bridge: Consequences Consequences: Client is shielded from abstract and concrete implementations Interfaces and implementations may be tested separately

CS Composite: Representing Recursive Hierarchies Name: Composite design pattern Problem description: Represent a hierarchy of variable width and depth, so that the leaves and composites can be treated uniformly through a common interface.

CS Composite: Class Diagram Composite Leaf Component * Client

CS Composite: Representing Recursive Hierarchies Solution: The Component interface specifies the services that are shared between Leaf and Composite. A Composite has an aggregation association with Components and implements each service by iterating over each contained Component. The Leaf services do the actual work.

CS Composite: Consequences Consequences: Client uses the same code for dealing with Leaves or Composites. Leaf-specific behavior can be changed without changing the hierarchy. New classes of Leaves can be added without changing the hierarchy.

CS Command: Encapsulating Control Flow Name: Command design pattern Problem description: Encapsulates requests so that they can be executed, undone, or queued independently of the request. Solution: A Command abstract class declares the interface supported by all ConcreteCommands. ConcreteCommands encapsulate a service to be applied to a Receiver.

CS Command Example: Class Diagram for Match GameBoard Move play() replay() GameMove play() replay() Match invokes

CS Command: Class Diagram Receiver1 Command execute() ConcreteCommand1 execute() Invoker invokes

CS Command: Consequences Consequences: The object of the command (Receiver) and the algorithm of the command (ConcreteCommand) are decoupled. Invoker is shielded from specific commands. ConcreteCommands are objects. They can be created and stored. New ConcreteCommands can be added without changing existing code.

CS Proxy: Encapsulating Expensive Objects Name: Proxy design pattern Problem description: Improve performance or security of a system by delaying expensive computations, using memory only when needed, or checking access before loading an object into memory. Solution: The ProxyObject class acts on behalf of a RealObject class. Both implement the same interface. ProxyObject stores a subset of the attributes of RealObject. ProxyObject handles certain requests, whereas others are delegated to RealObject. After delegation, the RealObject is created and loaded into memory.

CS Proxy: Example An abstract class SortStrings defines an interface to sorting lists of strings. ProxySortStrings is a class that sorts lists of strings very quickly in memory and delegates larger lists. RealSortStrings is a class that sorts very large lists of strings, but is expensive to create and execute on small lists.

CS Proxy: Class Diagram Object filename op1() op2() RealObject data:byte[] op1() op2() ProxyObject filename op1() op2() Client

CS Proxy: Consequences Consequences: Adds a level of indirection between Client and RealObject. The Client is shielded from any optimization for creating RealObjects.

CS Observer: Encapsulating Control Flow Name: Observer design pattern Problem description: Maintains consistency across state of one Subject and many Observers. Solution: A Subject has a primary function to maintain some state (e.g., a data structure). One or more Observers use this state, which introduces redundancy between the states of Subject and Observer. Observer invokes the subscribe() method to synchronize the state. Whenever the state changes, Subject invokes its notify() method to iteratively invoke each Observer.update() method.

CS Observer: Class Diagram Subject subscribe() unsubscribe() notify() subscribers ConcreteSubject state getstate() setstate() Observer update() ConcreteObserver observeState update() 1 *

CS Observer: Consequences Consequences: Decouples Subject, which maintains state, from Observers, who make use of the state. Can result in many spurious broadcasts when the state of Subject changes.

CS Abstract Factory: Encapsulating Platforms Name: Abstract Factory design pattern Problem description: Shield the client from different platforms that provide different implementations of the same set of concepts Example: A user interface must have versions that implement the same set of concepts for several windowing systems, e.g., scroll bars, buttons, highlighting, etc.

CS Abstract Factory: Encapsulating Platforms Solution: A platform (e.g., the application for a specific windowing system) is represented as a set of AbstractProducts, each representing a concept (e.g., button). An AbstractFactory class declares the operations for creating each individual product. A specific platform is then realized by a ConcreteFactory and a set of ConcreteProducts.

CS Abstract Factory: Class Diagram ClientAbstractFactory createProductA createProductB AbstractProductA AbstractProductB

CS Abstract Factory: Class Diagram ClientAbstractFactory createProductA ConcreteFactory1 createProductA AbstractProductA ProductA There could be several ConcreteFactory classes, each a subclass of AbstractFactory,

CS Abstract Factory: Class Diagram ClientAbstractFactory createProductA createProductB ConcreteFactory1 createProductA createProductB AbstractProductA ProductA There could be several ConcreteFactory classes, each a subclass of AbstractFactory. AbstractProductB ProductB

CS Abstract Factory: Consequences Consequences: Client is shielded from concrete products classes Substituting families at runtime is possible Adding new products is difficult since new realizations must be created for each factory

CS Abstract Factory: Discussion Discussion See the interesting discussion in Wikipedia (March 24, 2009) "Use of this pattern makes it possible to interchange concrete classes without changing the code that uses them, even at runtime. However, employment of this pattern, as with similar design patterns, may result in unnecessary complexity and extra work in the initial writing of code."