Chapter 8, Object Design Reuse and Patterns II

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 Reuse and Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
Chapter 8, Object Design Introduction to Design Patterns
CS350/550 Software Engineering Lecture 1. Class Work The main part of the class is a practical software engineering project, in teams of 3-5 people There.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Design Pattern – Bridge (Structural) References Yih-shoung Chen, Department of Information Engineering, Feng Chia University,Taiwan, R.O.C. The Bridge.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Reuse Activities Selecting Design Patterns and Components
Chapter 8, Object Design Reuse and Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
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 Object Design II: Design Patterns Bernd Bruegge Applied Software Engineering Technische.
Design Patterns: Structural Design Patterns
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Outline of the Lecture  Patterns covered  Composite:
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1.
CEN 4010 Ninth Lecture March 4, 2005 Introduction to Software Engineering (CEN-4010) Spring 2005 Instructor: Masoud Sadjadi
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Structural Design Patterns
ECE450S – Software Engineering II
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Introduction to Design Patterns.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 5150 Software Engineering Lecture 16 Program Design 3.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
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.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Chapter 8 Object Design: Reuse and Patterns.
Review of last class Software Engineering Modeling Problem Solving
Chapter 8 Object Design: Reuse and Patterns 2.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Design Patterns: Brief Examples
Object Design II: Design Patterns
Object-Oriented Analysis and Design
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Object-Oriented Software Engineering Using UML, Patterns, and Java,
Instructor: Dr. Hany H. Ammar
Chapter 8 Object Design: Reuse and Patterns 2.
Chapter 8, Design Patterns Bridge
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Chapter 8 Object Design: Reuse and Patterns.
Chapter 6, System Design Design Patterns
Presented by Igor Ivković
Chapter 8, Object Design Introduction to Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Structural Patterns: Adapter and Bridge
Chapter 8, Design Patterns Composite
Software Design Lecture : 35.
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Chapter 8 - Design Strategies
Chapter 8, DesignPatterns Facade
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Presentation transcript:

Chapter 8, Object Design Reuse and Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design Reuse and Patterns II

During Object Modeling we do many transformations and changes to the object model. It is important to make sure the object design model stays simple! In the next two lectures we show how to use design patterns to keep system models simple.

Modeling Heuristics Modeling must address our mental limitations: Our short-term memory has only limited capacity (7+-2) Good Models deal with this limitation, because they Do not tax the mind A good model requires only a minimal mental effort to understand Reduce complexity Turn complex tasks into easy ones (by good choice of representation) Use of symmetries Use abstractions Ontologies and taxonomies Have organizational structure: Memory limitations are overcome with an appropriate representation (“natural model”)

Outline of the Lecture Design Patterns Usefulness of design patterns Design Pattern Categories Patterns covered in this lecture Composite: Model dynamic aggregates Facade: Interfacing to subsystems Adapter: Interfacing to existing systems (legacy systems) Bridge: Interfacing to existing and future systems Patterns covered in the next lecture Abstract Factory Proxy Command Observer Strategy

Finding Objects The hardest problems in object-oriented system development are: Identifying objects Decomposing the system into objects Requirements Analysis focuses on application domain: Object identification System Design addresses both, application and implementation domain: Subsystem Identification Object Design focuses on implementation domain: Additional solution objects

Techniques for Finding Objects Requirements Analysis Start with Use Cases. Identify participating objects Textual analysis of flow of events (find nouns, verbs, ...) Extract application domain objects by interviewing client (application domain knowledge) Find objects by using general knowledge System Design Subsystem decomposition Try to identify layers and partitions Object Design Find additional objects by applying implementation domain knowledge

Another Source for Finding Objects : Design Patterns What are Design Patterns? A design pattern describes a problem which occurs over and over again in our environment Then it describes the core of the solution to that problem, in such a way that you can use the this solution a million times over, without ever doing it the same twice

What is common between these definitions? Definition Software System A software system consists of subsystems which are either other subsystems or collection of classes Definition Software Lifecycle: The software lifecycle consists of a set of development activities which are either other activities or collection of tasks

Introducing the Composite Pattern Models tree structures that represent part-whole hierarchies with arbitrary depth and width. The Composite Pattern lets client treat individual objects and compositions of these objects uniformly Client <<abstract>> Component Leaf Operation() Composite Operation() AddComponent RemoveComponent() GetChild() Children

What is common between these definitions? Software System: Definition: A software system consists of subsystems which are either other subsystems or collection of classes Composite: Subsystem (A software system consists of subsystems which consists of subsystems , which consists of subsystems, which...) Leaf node: Class Software Lifecycle: Definition: The software lifecycle consists of a set of development activities which are either other actitivies or collection of tasks Composite: Activity (The software lifecycle consists of activities which consist of activities, which consist of activities, which....) Leaf node: Task

Modeling a Software System with a Composite Pattern User Software System * Class Subsystem Children

Modeling the Software Lifecycle with a Composite Pattern Manager Software Lifecycle * Task Activity Children

The Composite Patterns models dynamic aggregates Fixed Structure: Car * * Battery Engine Doors Wheels Organization Chart (variable aggregate): * School * What you are seeing on this slide are what I would like to call patterns for analysis. A pattern is a recurring theme, something once you get used to see something this way, allows you to very fast understand a situation. It is well known, that if you show a set of chess positions of middle games tochess masters and non chess players, that chess masters are able to reconstruct these games without any effort. However, if you give them random chess configurations, chess masters are about as bad as non-chess players in reconstructing the boards. This tells you about the value of patterns. I would like you to learn about these aggregation patterns. In fact, I challenge you to see for your team and subsystem, if any of the analysis problems you face, can be cast in terms of one of the 3 patterns above. University Department Dynamic tree (recursive aggregate): Composite Pattern Dynamic tree (recursive aggregate): Program * * Block Compound Simple Statement Statement

Graphic Applications also use Composite Patterns The Graphic Class represents both primitives (Line, Circle) and their containers (Picture) Client Graphic Circle Draw() Picture Add(Graphic g) RemoveGraphic) GetChild(int) Children Line

Java‘s AWT library can be modeled with the component pattern Graphics Component Button TextField Label * TextArea Text Container add(Component c) paint(Graphics g) getGraphics()

Design Patterns reduce the Complexity of Models To communicate a complex model we use navigation and reduction of complexity We do not simply use a picture from the CASE tool and dump it in front of the user The key is navigate through the model so the user can follow it. We start with a very simple model and then decorate it incrementally Start with key abstractions (use animation) Then decorate the model with the additional classes To reduce the complexity of the model even further, we Apply the use of inheritance (for taxonomies, and for design patterns) If the model is still too complex, we show the subclasses on a separate slide Then identify (or introduced) patterns in the model We make sure to use the name of the patterns

Example: A More Complex Model of a Software Project Basic Abstractions Taxonomies Composite Patterns This model is already much more complex than the model shown on the previous slide. Its purpose is still for communication only. Because it already has quite a number of abstractions, It can only be understood if we communicate the model well to the user. We can do this by navigating through the model and highlight basic abstractions and typical patterns. For example, we can highlight the basic abstraction (the ones used in the previous slide) <<Proceed to first animation>> and tell the listener that these are the abstraction used in the previous slide (to make the point more clear, the instructor can move once more to the previous slide) To reduce the complexity of the model, the instructor can then point out that Work Product, Task and Participant all are now basic leaves in a composite pattern. <<Proceed to the next animation, show the use of the composite patterns>>. To reduce the complexity even further, the instructor finally points out the use of inheritance for the taxonomies (Resource, Staff, Work Product and Activity) Given these three tips, the students should be able to understand the model themselves.

Exercise Redraw the complete model for Project from your memory using the following knowledge The key abstractions are task, schedule, and participant Workproduct, Task and Participant are modeled with composite patterns, for example There are taxonomies for each of the key abstractions You have 5 minutes! Work Product *

Adapter pattern Delegation is used to bind an Adapter and an Adaptee Client ClientInterface Request() LegacyClass ExistingRequest() adaptee Adapter Request() Delegation is used to bind an Adapter and an Adaptee Interface inheritance is use to specify the interface of the Adapter class. Target and Adaptee (usually called legacy system) pre-exist the Adapter. Target may be realized as an interface in Java.

Adapter Pattern “Convert the interface of a class into another interface clients expect.” The adapter pattern lets classes work together that couldn’t otherwise because of incompatible interfaces Used to provide a new interface to existing legacy components (Interface engineering, reengineering). Also known as a wrapper Two adapter patterns: Class adapter: Uses multiple inheritance to adapt one interface to another Object adapter: Uses single inheritance and delegation Object adapters are much more frequent. We will only cover object adapters (and call them therefore simply adapters)

Bridge Pattern Use a bridge to “decouple an abstraction from its implementation so that the two can vary independently”. (From [Gamma et al 1995]) Also know as a Handle/Body pattern. Allows different implementations of an interface to be decided upon dynamically.

(in Vehicle Subsystem) Using a Bridge The bridge pattern is used to provide multiple implementations under the same interface. Examples: Interface to a component that is incomplete, not yet known or unavailable during testing JAMES Project: if seat data is required to be read, but the seat is not yet implemented, known, or only available by a simulation, provide a bridge: Seat (in Vehicle Subsystem) VIP imp SeatImplementation GetPosition() SetPosition() Stub Code AIMSeat SARTSeat

Seat Implementation public interface SeatImplementation { public int GetPosition(); public void SetPosition(int newPosition); } public class Stubcode implements SeatImplementation { public int GetPosition() { // stub code for GetPosition ... public class AimSeat implements SeatImplementation { // actual call to the AIM simulation system …. public class SARTSeat implements SeatImplementation { // actual call to the SART seat simulator

Bridge Pattern

Adapter vs Bridge Similarities: Difference: Both are used to hide the details of the underlying implementation. Difference: The adapter pattern is geared towards making unrelated components work together Applied to systems after they’re designed (reengineering, interface engineering). A bridge, on the other hand, is used up-front in a design to let abstractions and implementations vary independently. Green field engineering of an “extensible system” New “beasts” can be added to the “object zoo”, even if these are not known at analysis or system design time.

Facade Pattern Provides a unified interface to a set of objects in a subsystem. A facade defines a higher-level interface that makes the subsystem easier to use (i.e. it abstracts out the gory details) Facades allow us to provide a closed architecture

Design Example Subsystem 1 can look into the Subsystem 2 (vehicle subsystem) and call on any component or class operation at will. This is “Ravioli Design” Why is this good? Efficiency Why is this bad? Can’t expect the caller to understand how the subsystem works or the complex relationships within the subsystem. We can be assured that the subsystem will be misused, leading to non-portable code Subsystem 1 Subsystem 2 Seat Card AIM SA/RT

Subsystem Design with Façade, Adapter, Bridge The ideal structure of a subsystem consists of an interface object a set of application domain objects (entity objects) modeling real entities or existing systems Some of the application domain objects are interfaces to existing systems one or more control objects We can use design patterns to realize this subsystem structure Realization of the Interface Object: Facade Provides the interface to the subsystem Interface to existing systems: Adapter or Bridge Provides the interface to existing system (legacy system) The existing system is not necessarily object-oriented!

Realizing an Opaque Architecture with a Facade VIP Subsystem The subsystem decides exactly how it is accessed. No need to worry about misuse by callers If a façade is used the subsystem can be used in an early integration test We need to write only a driver Vehicle Subsystem API Card Seat AIM SA/RT

Design Patterns encourage reusable Designs A facade pattern should be used by all subsystems in a software system. The façade defines all the services of the subsystem. The facade will delegate requests to the appropriate components within the subsystem. Most of the time the façade does not need to be changed, when the component is changed, Adapters should be used to interface to existing components. For example, a smart card software system should provide an adapter for a particular smart card reader and other hardware that it controls and queries. Bridges should be used to interface to a set of objects where the full set is not completely known at analysis or design time. when the subsystem must be extended later after the system has been deployed and client programs are in the field(dynamic extension). Model/View/Controller should be used when the interface changes much more rapidly than the application domain.

Summary Design patterns are partial solutions to common problems such as such as separating an interface from a number of alternate implementations wrapping around a set of legacy classes protecting a caller from changes associated with specific platforms. A design pattern is composed of a small number of classes use delegation and inheritance provide a robust and modifiable solution. These classes can be adapted and refined for the specific system under construction. Customization of the system Reuse of existing solutions

Summary II Composite Pattern: Facade Pattern: Adapter Pattern: Models trees with dynamic width and dynamic depth Facade Pattern: Interface to a subsystem closed vs open architecture Adapter Pattern: Interface to reality Bridge Pattern: Interface to reality and prepare for future

Additional Design Heuristics Never use implementation inheritance, always use interface inheritance A subclass should never hide operations implemented in a superclass If you are tempted to use implementation inheritance, use delegation instead