Chapter 8, Object Design: Reuse and Patterns

Slides:



Advertisements
Similar presentations
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Advertisements

Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns (Lecture I)
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns.
NJIT Use Case Model Operation Contracts Prepared By: Sumit Sharma.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns I.
Use Cases Chapter 4. After Scenarios Find all the use cases in the scenario that specifies all possible instances of how to report a fire –Ex: “Report.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns I.
Object Design I: Reuse.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Design Patterns.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Detailed Design Overview and Mid-Level Class Modeling.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
Class Diagrams Identifying and representing Classes Object Web, Bapayya Choudhary Maganti.
© 2005 Prentice Hall9-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Oct. 16, 2003CS WPI1 CS 509 Design of Software Systems Lecture #7 Thursday, Oct. 16, 2003.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Class Design. Class Design The analysis phase determines what the implementation must do, and the system design.
Why is Design so Difficult? Analysis: Focuses on the application domain Design: Focuses on the solution domain –The solution domain is changing very rapidly.
Review of last class Software Engineering Modeling Problem Solving
CompSci 280 S Introduction to Software Development
CompSci 280 S Introduction to Software Development
Chapter 8 Object Design: Reuse and Patterns 1.
Module Road Map Refactoring Why Refactoring? Examples
Chapter 5 – Design and Implementation
Chapter 11 Object-Oriented Design
Unified Modeling Language
Data Abstraction: The Walls
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Week 10: Object Modeling (1)Use Case Model
Component Based Software Engineering
TIM 58 Chapter 8: Class and Method Design
Chapter 9, Object Design: Specifying Interfaces
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
INFS 6225 – Object-Oriented Systems Analysis & Design
Chapter 8, Object Design: Reuse and Patterns
Object Oriented Analysis and Design
Overview of Eclipse Lectures
Chapter 5 Designing the Architecture Shari L. Pfleeger Joanne M. Atlee
Introduction to Software Engineering (CEN-4010)
CIS 375 Bruce R. Maxim UM-Dearborn
Starting Design: Logical Architecture and UML Package Diagrams
Software Engineering with Reusable Components
An Introduction to Software Architecture
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Chapter 8, Object Design: Reuse and Patterns
Chapter 17 - Component-based software engineering
Chapter 8, Object Design: Reuse and Patterns I
Design Yaodong Bi.
CIS 375 Bruce R. Maxim UM-Dearborn
Chapter 8, Design Patterns Introduction
Object Oriented System Design Class Diagrams
HFOOAD Chapter 5 Interlude
Design Contracts and Errors A Software Development Strategy
Presentation transcript:

Chapter 8, Object Design: Reuse and Patterns

Object Design Purpose of object design: Prepare for the implementation of the system model based on design decisions Transform the system model (optimize it) Investigate alternative ways to implement the system model Use design goals: minimize execution time, memory and other measures of cost. Object design serves as the basis of implementation. O bject design is the process of adding details to the requirements analysis and making implementation decisions The object designer must choose among different ways to implement the analysis model with the goal to minimize execution time, memory and other measures of cost. Requirements Analysis: Use cases, functional and dynamic model deliver operations for object model Object Design: Iterates on the models, in particular the object model and refine the models Object Design serves as the basis of implementation

Terminology: Naming of Design Activities Methodology: Object-oriented software engineering (OOSE) System Design Decomposition into subsystems, etc Object Design Data structures and algorithms chosen Implementation Implementation language is chosen Object-Oriented methodologies use these terms: The System Design activity involves the decomposition of the system into subystems

System Development as a Set of Activities System Model Existing Machine Problem Application objects Analysis Solution objects Design Off-the-shelf components are also sometimes called COTS (commercial off-the-shelf components) Custom objects - Object Design Off-the-Shelf Components - System Design

Object Design consists of 4 Activities 1. Reuse: Identification of existing solutions Use of inheritance Off-the-shelf components and additional solution objects Design patterns 2. Interface specification Describes precisely each class interface 3. Object model restructuring Transforms the object design model to improve its understandability and extensibility 4. Object model optimization Transforms the object design model to address performance criteria such as response time or memory utilization.

Object Design Activities Specifying constraints Specifying types & signatures Identifying patterns Adjusting patterns Identifying missing attributes & operations Specifying visibility Specification Specifying exceptions Reuse Identifying components Adjusting components Select Subsystem A Detailed View of Object Design Activities

Detailed View of Object Design Activities (ctd) Collapsing classes Restructuring Optimization Revisiting inheritance Optimizing access paths Caching complex computations Delaying complex Check Use Cases Realizing associations

One Way to do Object Design Identify the missing components in the design gap Make a build or buy decision to obtain the missing component => Component-Based Software Engineering: The design gap is filled with available components (“0 % coding”). Special Case: COTS-Development COTS: Commercial-off-the-Shelf The design gap is completely filled with commercial-off-the-shelf-components. => Design with standard components.

Identification of new Objects during Object Design Requirements Analysis (Language of Application Domain) Incident Report Text box Menu Scrollbar Incident Report Object Design (Language of Solution Domain)

Application Domain vs Solution Domain Objects Requirements Analysis (Language of Application Domain) Subject Observer * observers subscribe(subscriber) unsubscribe(subscriber) notify() update() Object Design (Language of Solution Domain) ConcreteSubject state getState() setState() ConcreteObserver observeState update()

Other Reasons for new Objects The implementation of algorithms may necessitate objects to hold values New low-level operations may be needed during the decomposition of high-level operations Example: EraseArea() in a drawing program Conceptually very simple Implementation is complicated: Area represented by pixels We need a Repair() operation to clean up objects partially covered by the erased area We need a Redraw() operation to draw objects uncovered by the erasure We need a Draw() operation to erase pixels in background color not covered by other objects. New objects are often needed during object design: Let’s take as an example: The EraseArea() operation in a drawing program. Conceptually it is very simple, the Implementation Is much more complicated

Modeling of the Real World Modeling of the real world leads to a system that reflects today’s realities but not necessarily tomorrow’s. There is a need for reusable and flexible designs Design knowledge such as the adapter pattern complements application domain knowledge and solution domain knowledge.

Reuse of Code I have a list, but my customer would like to have a stack The list offers the operations Insert(), Find(), Delete() The stack needs the operations Push(), Pop() and Top() Can I reuse the existing list? I am an employee in a company that builds cars with expensive car stereo systems Can I reuse the existing car software in a home stero system?

Reuse of existing classes I have an implementation for a list of elements of Typ int Can I reuse this list to build a list of customers a spare parts catalog a flight reservation schedule? I have developed a class “Addressbook” in another project Can I add it as a subsystem to my e-mail program which I purchased from a vendor (replacing the vendor-supplied addressbook)? Can I reuse this class in the billing software of my dealer management system?

Customization: Build Custom Objects Problem: Close the object design gap Develop new functionality Main goal: Reuse knowledge from previous experience Reuse functionality already available Composition (also called Black Box Reuse) New functionality is obtained by aggregation The new object with more functionality is an aggregation of existing objects Inheritance (also called White-box Reuse) New functionality is obtained by inheritance Problem formulation for customization Develop this new functionality as a set of operations of a new class or adapt an existing program to a new environment or a new customer. So the goal is to produce custom objects to close the object design gap.

Inheritance comes in many Flavors Inheritance is used in four ways: Specialization Generalization Specification Inheritance Implementation Inheritance.

Discovering Inheritance To “discover“ inheritance associations, we can proceed in two ways, which we call specialization and generalization Generalization: the discovery of an inheritance relationship between two classes, where the sub class is discovered first. Specialization: the discovery of an inheritance relationship between two classes, where the super class is discovered first. The distinction is subtle and depends on who is discovered first, the super class or the sub class

Generalization Example: Modeling a Coffee Machine VendingMachine Generalization: The class CoffeeMachine is discovered first, then the class SodaMachine, then the superclass VendingMachine After the generalization there is often an opportunity for Restructuring: Why don‘t we move the methods totalReceipts, collectMoney(), makeChange(), dispenseBeverage() into the super class? totalReceipts numberOfCups coffeeMix collectMoney() makeChange() heatWater() dispenseBeverage() addSugar() addCreamer() CoffeeMachine

Restructuring of Attributes and Operations is often a Consequence of Generalization Called Remodeling if done on the model level; Called Refactoring if done on the source code level. totalReceipts collectMoney() makeChange() dispenseBeverage() VendingMachine numberOfCups coffeeMix heatWater() addSugar() addCreamer() CoffeeMachine cansOfBeer cansOfCola chill() SodaMachine totalReceipts numberOfCups coffeeMix collectMoney() makeChange() heatWater() dispenseBeverage() addSugar() addCreamer() CoffeeMachine VendingMachine

An Example of a Specialization CandyMachine is a new product and designed as a sub class of the superclass VendingMachine numberOfCups coffeeMix heatWater() addSugar() addCreamer() CoffeeMachine totalReceipts collectMoney() makeChange() dispenseBeverage() VendingMachine cansOfBeer cansOfCola chill() SodaMachine A change of names might now be useful: dispenseItem() instead of dispenseBeverage() and dispenseSnack() bagsofChips numberOfCandyBars dispenseSnack() CandyMachine

Example of a Specialization (2) numberOfCups coffeeMix heatWater() addSugar() addCreamer() dispenseItem() CoffeeMachine totalReceipts collectMoney() makeChange() VendingMaschine cansOfBeer cansOfCola chill() SodaMachine bagsofChips numberOfCandyBars CandyMachine Now we have the method dispenseItem in the superclass! It should be an abstract method, implemented by each of the subclasses

Meta-Model for Inheritance Object Design Analysis activity Inheritance is used during analysis as well as during object design! This is often confusing for modeling novices Taxonomy Inheritance for Reuse Specification Inheritance Implementation Inheritance Inheritance detected by Inheritance detected by specialization generalization

For Reuse: Implementation Inheritance and Specification Inheritance Also called class inheritance Goal: Extend an applications’ functionality by reusing functionality from the super class Inherit from an existing class with some or all operations already implemented Specification Inheritance Also called subtyping Inherit from a specification The specification is an abstract class with all operations specified, but not yet implemented.

Example for Implementation Inheritance A very similar class is already implemented that does almost the same as the desired class implementation Add() Remove() List Example: • I have a List class, I need a Stack class • How about subclassing the Stack class from the List class and implementing Push(), Pop(), Top() with Add() and Remove()? “Already implemented” Push () Pop() Stack Top() Inheritance is a generalization technique, in which the behavior of a superclass is shared by all its subclasses. Sometimes it is misused as an implementation technique. Question: Can you give me an example for unwanted behavior? Problem with implementation inheritance: The inherited operations might exhibit unwanted behavior. Example: What happens if the Stack user calls Remove() instead of Pop()?

Delegation instead of Implementation Inheritance Inheritance: Extending a Base class by a new operation or overriding an operation. Delegation: Catching an operation and sending it to another object. Which of the following models is better? +Add() +Remove() List Stack +Push() +Pop() +Top() +Push() +Pop() +Top() Stack Add() Remove() List

Delegation Delegation is a way of making composition as powerful for reuse as inheritance In delegation two objects are involved in handling a request from a Client The Receiver object delegates operations to the Delegate object The Receiver object makes sure, that the Client does not misuse the Delegate object. delegates to Client Receiver Delegate calls

Revised Metamodel for Inheritance Object Design Analysis activity Taxonomy Inheritance for Reuse This is the final metamodel for modeling inheritance. Today we have added strict inheritance and contractions as two additional ways to use implementation inheritance: We identified strict inheritance as a good citizen, and if used this way, then implementation inheritance is a good thing. And we have shown that contract is a bad idea, because it leads to unmaintainable systems and unpredictable behavior. Specification Inheritance Implementation Inheritance Inheritance detected by Inheritance detected by specialization generalization Strict Inheritance Contraction

Documenting Object Design: ODD Conventions Each subsystem in a system provides a service Describes the set of operations provided by the subsystem Specification of the service operations Signature: Name of operation, fully typed parameter list and return type Abstract: Describes the operation Pre: Precondition for calling the operation Post: Postcondition describing important state after the execution of the operation Use JavaDoc and Contracts for the specification of service operations Each subsystem in a system provides a service (see Chapters on System Design) Describes the set of operations provided by the subsystem Specifying a service operation as Signature: Name of operation, fully typed parameter list and return type Abstract: Describes the operation Pre: Precondition for calling the operation Post: Postcondition describing important state after the execution of the operation Use JavaDoc for the specification of service operations.

Package it all up Pack up design into discrete units that can be edited, compiled, linked, reused Construct physical modules Ideally use one package for each subsystem System decomposition might not be good for implementation. Two design principles for packaging Minimize coupling: Classes in client-supplier relationships are usually loosely coupled Avoid large number of parameters in methods to avoid strong coupling (should be less than 4-5) Avoid global data Maximize cohesion: Put classes connected by associations into one package.

Packaging Heuristics Each subsystem service is made available by one or more interface objects within the package Start with one interface object for each subsystem service Try to limit the number of interface operations (7+-2) If an interface object has too many operations, reconsider the number of interface objects If you have too many interface objects, reconsider the number of subsystems Interface objects vs Java interface: Interface object: Used during requirements analysis, system design, object design. Denotes a service or API Java interface: Used during implementation in Java (May or may not implement an interface object).