Lecture Notes on. Object Design. Object Design. Bill Scherlis / Bernd Brügge Software Engineering Fall October November 1999

Similar documents
Chapter 9 Object Design: Specifying Interfaces

9. Object Design: Specifying Interfaces

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/03/2015

Software Engineering Fall 2014

Chapter 8: Class and Method Design

Chapter 9, Object Design: Specifying Interfaces

Chapter 9, Object Design: Specifying Interfaces

Chapter 10, Mapping Models to Code

10. Mapping Models to Code

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

INTERNAL ASSESSMENT TEST III Answer Schema

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Chapter 8, Object Design: Reuse and Patterns

Chapter 5 Object-Oriented Programming

Appendix A - Glossary(of OO software term s)

Object-Oriented Software Engineering Practical Software Development using UML and Java

Object-Oriented Design

Chapter 1: Principles of Programming and Software Engineering

Lethbridge/Laganière 2005 Chapter 9: Architecting and designing software 6

Summary of the course lectures

340 Review Fall Midterm 1 Review

CSE 70 Final Exam Fall 2009

09. Component-Level Design

Chapter 8, Object Design: Reusing Pattern Solutions

Object Design: Reuse, Part 2

Interface (API) Design

Topic : Object Oriented Design Principles

PC204. Lecture 5 Programming Methodologies. Copyright 2000 by Conrad Huang and the Regents of the University of California. All rights reserved.

Chapter 10 Object-Oriented Design Principles

Object-Oriented Concepts and Design Principles

PROGRAMMING LANGUAGE 2

Chapter 1: Programming Principles

DESIGN PATTERN - INTERVIEW QUESTIONS

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Object-Oriented Design

Chapter 4 Defining Classes I

BCS Higher Education Qualifications. Diploma in IT. Object Oriented Programming Syllabus

Advanced Database Applications. Object Oriented Database Management Chapter 13 10/29/2016. Object DBMSs

What is Software Architecture

The Software Design Process. CSCE 315 Programming Studio, Fall 2017 Tanzir Ahmed

Principles of Object-Oriented Design

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Testing Object-Oriented Software. 22 November 2017

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

Top Down Design vs. Modularization

COURSE 2 DESIGN PATTERNS

Software Design Fundamentals. CSCE Lecture 11-09/27/2016

TOPLink for WebLogic. Whitepaper. The Challenge: The Solution:

CHAPTER 9 DESIGN ENGINEERING. Overview

Java Object Oriented Design. CSC207 Fall 2014

Component-Level Design. Slides copyright 1996, 2001, 2005, 2009 by Roger S. Pressman. For non-profit educational use only

ACRONYMS AND GLOSSARY

AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz

Inheritance (Chapter 7)

Design Concepts and Principles

Lecture Chapter 2 Software Development

OO Technology: Properties and Limitations for Component-Based Design

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Object-Oriented Design

CMPT Data and Program Organization

In this Lecture you will Learn: Object Design. Information Sources for Object Design. Class Specification: Attributes

Object-Oriented Design and Modeling Using the UML

Abstraction. Design fundamentals in OO Systems. Fundamental Software Development Principles

Design Concepts. Slide Set to accompany. Software Engineering: A Practitioner s Approach, 7/e by Roger S. Pressman

Design Patterns V Structural Design Patterns, 2

CS342: Software Design. November 21, 2017

Introduction to System Design

Data Structures (list, dictionary, tuples, sets, strings)

Recap : UML artefacts. Black Box Requirements. Functional Specification. System. System. Test. Design. System. System. Development.

CHAPTER 5 GENERAL OOP CONCEPTS

Objectives. Explain the purpose and objectives of objectoriented. Develop design class diagrams

Design by Contract in Eiffel

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Object- Oriented Design with UML and Java Part I: Fundamentals

Type Hierarchy. Lecture 6: OOP, autumn 2003

How We Refactor, and How We Know It

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

Concepts of Programming Languages

Review -- an Exercise. Use the Elevator example as a context, develop a: Use case diagram Class diagram Sequence diagram Start Chart diagram

Object-Oriented Design

Inheritance. Quick Review of Last Lecture. November 12, Passing Arguments. Passing Arguments. Variable Assignment Revisited

Design Engineering. Dr. Marouane Kessentini Department of Computer Science

About this module. Object-oriented analysis and design. About this module. Analysis

Goals of design. satisfies problem requirements, usable error free, resistant to incorrect input. readable, not purposefully cryptic.

Effective Modular Design

Patterns and Testing

Low Level Design Activities. Implementation (Low Level Design) What is a Good Low Level Module? Black Box Aspects. Black box aspects White box aspects

Design Patterns Design patterns advantages:

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

SE 1: Software Requirements Specification and Analysis

Agent-Enabling Transformation of E-Commerce Portals with Web Services

Introduction to Software Engineering. 5. Modeling Objects and Classes

Basic Object-Orientation

CSCU9T4: Managing Information

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

ITI Introduction to Computing II

Transcription:

v 8 September 1994 Lecture Notes on Object Design Object Design Bill Scherlis / Bernd Brügge 15-413 Software Engineering Fall 1999 21 October 1999 2 November 1999 Bruegge/Software 15-413 Software Engineering Fall 1999 1 2

Object Design The Basis for Implementation Object Design Add details to requrements analysis Make implementation decisions: Build / Buy Make implementation decisions: Solution objects Design drivers Time. Cost. Quality / assurance. Features / capability. Performance. Future. Product line context. Operations in the object model Requirements Analysis: Use cases, functional and dynamic models deliver operations for object model Object Design: Iterate on where to put these operations in the object model Bruegge/Software 15-413 Software Engineering Fall 1999 2

Build / Buy Buy Cost Project resources Development time Market leverage Ride growth curves Quality Adoption cost Build Availability Risk Control over process Future trajectory Support: Small vendor Support: Large vendor Architectural Certification Bruegge/Software 15-413 Software Engineering Fall 1999 3

Object Design: Closing the Gap System Problem Application objects Requirements gap Solution objects Custom objects Object design gap Off-the-shelf components System design gap Machine Bruegge/Software 15-413 Software Engineering Fall 1999 4

Example Object Design Issues Full definition of associations Full definition of classes Encapsulation of algorithms and data structures Detection of new application-domain independent classes (example: Cache) Optimization Increase of inheritance Decision on control Packaging Bruegge/Software 15-413 Software Engineering Fall 1999 5

Example Object Design Criteria Rate of change Of requirements Of OTS environment Relatedness within product line Performance sensitivity Division of labor, division of expertise Tolerance for interdependency Bruegge/Software 15-413 Software Engineering Fall 1999 6

Object Design Activities 1. Service specification Describes precisely each class interface 2. Component selection Identify off-the-shelf components and additional solution objects 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. Bruegge/Software 15-413 Software Engineering Fall 1999 7

Object Design Concepts Solution Objects Objects in the implementation domain Signatures Classes, Interfaces Methods, Fields Packages Contracts Invariants, Preconditions, Postconditions Mechanical attributes Specification UML Object Constraint Language (OCL) Bruegge/Software 15-413 Software Engineering Fall 1999 8

Specification 1 UML Object Constraint Language (OCL) Context Hashtable inv: numelements >= 0 context Hashtable::put(key, entry) pre:!containskey(key) context Hashtable::put(key, entry) post: containskey(key) and get(key) = entry and numelements = numelements@pre + 1 Bruegge/Software 15-413 Software Engineering Fall 1999 9

Specification 2 Examples Textual description of invariants, preconditions, postconditions. Typical: Data invariant for complex types Often used in code walkthroughs State machine for a class Lifetime of an object How an object responds to events Constraints on class clients: order of method calls, etc In general Range from informal to formal When is formal useful? Complex invariants and conditions High risk: consequences of error Bruegge/Software 15-413 Software Engineering Fall 1999 10

1. Service Specification Requirements analysis Identifies attributes and operations without specifying their types or their parameters. Object design Identify missing attributes, operations Specify details 1a. Type signature information 1b. Visibility information 1c. Contracts 1d. Exceptions Bruegge/Software 15-413 Software Engineering Fall 1999 11

GIS subsystems Visualization EmissionModeling GIS Simulation Storage Bruegge/Software 15-413 Software Engineering Fall 1999 12

GIS Object Model: Before Layer label RoadLayer WaterLayer PoliticalLayer Highway SecondaryRoad State County River Lake PolyLine Polygon Bruegge/Software 15-413 Software Engineering Fall 1999 13

GIS: From System Design to Object Design Task specification Subsystem model Use case: Zoom-the-Map Bruegge/Software 15-413 Software Engineering Fall 1999 14

GIS Object Model: After Layer label RoadLayer WaterLayer PoliticalLayer label LayerElement * elements LayerElement(polyline) LayerElement(polygon) getoutline(bbox,detail) Highway SecondaryRoad State County River Lake Bruegge/Software 15-413 Software Engineering Fall 1999 15

GIS Object Model: After +label:string Layer +Layer(label:String) +getoutline(bbox:rect2d, detail:double): Enumeration(LayerElement) Point -x,y:double -indetaillevels:set -notindetaillevel:set +Point(x,y:double) +excludeinlevel(level:double) +excludefromlevel(level:double) 1 +label:string LayerElement +LayerElement(pl:PolyLine) +getoutline(bbox:rect2d, detail:double): Enumeration(PolyLine) 1 1 polyline +label:string PolyLine +PolyLine() +getpoints(): Enumeration(Point) * points * * elements Bruegge/Software 15-413 Software Engineering Fall 1999 16

1a. Service Specification: Add Type Signatures -numelements:int +put() +get() +remove() +containskey() +size() Hashtable Hashtable -numelements:int +put(key:object,entry:object) +get(key:object):object +remove(key:object) +containskey(key:object):boolean +size():int Bruegge/Software 15-413 Software Engineering Fall 1999 17

1b. Service Specification: Add Visibility UML defines three levels of visibility: Private (= Java private): Private attributes/operations can be accessed/invoked only within the class in which they are defined. Private attributes/operations cannot be accessed by subclasses or other classes. Protected (nothing comparable in Java): Protected attributes/operations can be accessed by the class in which they are defined and in any descendent class. Public (= Java public): Public attributes/operations can be accessed by any class. Bruegge/Software 15-413 Software Engineering Fall 1999 18

Information Hiding : Why Encapsulate? Encapsulate Apply need to know principle. The less an operation knows...... the less likely it will be affected by any changes... the easier the class can be changed Build firewalls around classes Define public interfaces for classes as well as subsystems The classic trade-off Information hiding vs. efficiency Modularity vs. performance Bruegge/Software 15-413 Software Engineering Fall 1999 19

Information Hiding Design Principles Encapsulate attributes (fields) Only the operations of a class are allowed to manipulate its attributes Access attributes only via operations. Example: Java Beans (Exception: static finals) Encapsulate external objects at the subsystem boundary Define abstract class interfaces which mediate between system and external world as well as between subsystems Use combiners Do not apply an operation to the result of another operation. Write a new operation that combines the two operations. Bruegge/Software 15-413 Software Engineering Fall 1999 20

1c. Service Specification: Contracts Contracts on a class/method enable caller and callee to share assumptions about the class/method. Contracts include three types of constraints: Invariant: A predicate that is always true for instances of a class. Invariants are used to specify consistency constraints among class attributes. Precondition: A predicate that must be true before a specific operation is invoked. A constraint on a caller. Postcondition: A predicate that will be true after a specific operation has been invoked. A constraint on the operation. Bruegge/Software 15-413 Software Engineering Fall 1999 21

Specification UML Object Constraint Language (OCL) Truth-valued expressions. Not procedural. Context Hashtable inv: numelements >= 0 context Hashtable::put(key, entry) pre:!containskey(key) context Hashtable::put(key, entry) post: containskey(key) and get(key) = entry and numelements = numelements@pre + 1 Bruegge/Software 15-413 Software Engineering Fall 1999 22

Specification and OCL A constraint can also be depicted as a note attached to the constrained UML element by a dependency relationship. <<precondition>>!containskey(key) <<precondition>> containskey(key) <<precondition>> containskey(key) HashTable numelements:int put(key,entry:object) get(key):object remove(key:object) containskey(key:object):boolean size():int <<invariant>> numelements >= 0 <<postcondition>> get(key) == entry <<postcondition>>!containskey(key) Bruegge/Software 15-413 Software Engineering Fall 1999 23

GIS Specification Example context Point inv: Point.allInstances->forAll(p1,p2:Point (p1.x=p2.x and p1.y=p2.y) implies p1=p2) Bruegge/Software 15-413 Software Engineering Fall 1999 24

1d. Exceptions +label:string LayerElement +LayerElement(pl:PolyLine) +getoutline(bbox:rect2d, detail:double): Enumeration(PolyLine) <<pre>> bbox.width > 0 and bbox.height > 0 <<exception>> ZeroBoundingBox Bruegge/Software 15-413 Software Engineering Fall 1999 25

Object Design Areas 1. Service specification Describes precisely each class interface 2. Component selection Identify off-the-shelf components and additional solution objects 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. Bruegge/Software 15-413 Software Engineering Fall 1999 26

2. Component Selection The most important reuse decisions OTS components 2a. Select and adjust class libraries Examples: AWT, Swing/JFC, MFC, etc. 2b. Select and adjust application frameworks Examples: COM, Beans. Bruegge/Software 15-413 Software Engineering Fall 1999 27

Example: JFC adjustment <<JFC>> :JScrollPane detail :MapArea paintcontents() <<JFC>> :JFrame <<JFC>> :JPanel <<JFC>> :JToolbar... Issue: Line representation JFC: int[], int[] GIS: Approaches: Enum(Point) 1. Code translate method 2. Place the method: MapArea Layer Adapter Bruegge/Software 15-413 Software Engineering Fall 1999 28

Application Frameworks Example: Java Beans Event model Serialization Locks Fields Private Nomenclature Introspection Persistence Etc. Customization Frameworks Patterns Libraries Components The API Hourglass The Service Interface Bruegge/Software 15-413 Software Engineering Fall 1999 29

Object Design Areas 1. Service specification Describes precisely each class interface 2. Component selection Identify off-the-shelf components and additional solution objects 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. Bruegge/Software 15-413 Software Engineering Fall 1999 30

3. Restructuring Activities 3a. Realize associations 3b. Increase reuse 3c. Remove implementation dependencies Bruegge/Software 15-413 Software Engineering Fall 1999 31

3a. Realize Associations +label:string Layer +Layer(label:String) +getoutline(bbox:rect2d, detail:double): Enumeration(LayerElement) 1 +label:string LayerElement +LayerElement(pl:PolyLine) +getoutline(bbox:rect2d, detail:double): Enumeration(PolyLine) 1 1 pl +label:string * elements PolyLine +PolyLine() +getpoints(): Enumeration(Point) Bruegge/Software 15-413 Software Engineering Fall 1999 32

3a. Realize Associations Kinds / Dimensions 1-1, 1-many, many-many 0..1 Uni-/bi-directional Qualified Visibility Considerations Operations needed Performance References Implementation decisions Collections Use of separate objects Bruegge/Software 15-413 Software Engineering Fall 1999 33

Unidirectional 1-to-1 Association Object design model befor e transformation ZoomInAction 1 1 MapArea Object design model after transformation ZoomInAction MapArea targetmap:maparea Bruegge/Software 15-413 Software Engineering Fall 1999 34

Bidirectional 1-to-1 Association Object design model before transformation ZoomInAction 1 1 MapArea Object design model after transformation ZoomInAction -targetmap:maparea +gettargetmap() +settargetmap(map) MapArea -zoomin:zoominaction +getzoominaction() +setzoominaction(action) Bruegge/Software 15-413 Software Engineering Fall 1999 35

1-to-Many Association Object design model before transformation Layer 1 * LayerElement Object design model after transformation Layer -layerelements:set +elements() +addelement(le) +removeelement(le) LayerElement -containedin:layer +getlayer() +setlayer(l) Bruegge/Software 15-413 Software Engineering Fall 1999 36

Qualification Scenario simname 1 0..1 SimulationRun Scenario -runs:map +elements() +addrun(simname, sr:simulationrun) +removerun(simname, sr:simulationrun) SimulationRun -scenarios:vector +elements() +addscenario(s:scenario) +removescenario(s:scenario) Bruegge/Software 15-413 Software Engineering Fall 1999 37

3b. Increase Reuse Increase Inheritance In general: Taxonomy reflects understanding of application domain Rearrange and adjust classes/operations for inheritance Abstract common behavior from class groups Detect opportunities to hoist behaviors A subsystem could become a superclass. The cost of inheritance Performance: dynamic dispatch Recompilation Bruegge/Software 15-413 Software Engineering Fall 1999 38

Building a super class from several classes Prepare for inheritance. Refactor operations to have similar signatures: Fewer/mismatched arguments: Overload names Mismatched attribute names: Rename attribute, change operations. Abstract out the common behavior into supers Supers are desirable. Better modularity, extensibility and reusability Improved configuration management Bruegge/Software 15-413 Software Engineering Fall 1999 39

Inheritance: Good and Bad Kinds of Inheritance Interfaces Implementations The cost of implementation inheritance Code rot: Persistence of abstractions beyond their time Dependency on small local implementation decisions Data representations and invariants Example: Jframe and JInternalFrame Approaches Delegate, don t inherit Subclass delegates to the super Use abstract supers Proliferate interfaces Bruegge/Software 15-413 Software Engineering Fall 1999 40

Refactoring Reorganizing hierarchies, signatures, and collaborations Without changing overall system function (generally) Examples Moving from one taxonomy to another taxonomy Multiple inheritance to single inheritance Relocating methods within a hierarchy Renaming to exploit overloading I.e., hierarchy transparency at code level Bruegge/Software 15-413 Software Engineering Fall 1999 41

Object Design Areas 1. Service specification Describes precisely each class interface 2. Component selection Identify off-the-shelf components and additional solution objects 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. Bruegge/Software 15-413 Software Engineering Fall 1999 42

Design Optimizations Important part of the object design phase: Requirements analysis model is semantically correct but often too inefficient if directly implemented. Optimization activities during object design: 1. Add redundant associations to minimize access cost 2. Rearrange computations for greater efficiency 3. Store derived attributes to save recomputation time As an object designer you must strike a balance between efficiency and clarity. Optimizations will make your models more obscure Bruegge/Software 15-413 Software Engineering Fall 1999 43

Design Optimizations Necessary part of the object design phase: Requirements analysis model Semantically correct Well structured (modular) Probably too inefficient if directly implemented. Object designer: balance between efficiency and clarity. Efficiency: At run time, compile time, design time. Optimizations will make models more obscure Optimizations will make programs harder to evolve Bruegge/Software 15-413 Software Engineering Fall 1999 44

4. Design Optimization Activities 4a. Add redundant associations to reduce access cost What are the most frequent operations? Sensor data lookup? How often is the operation called? 30 times/month? 20 times/second? 4b. Turn classes into attributes to avoid recomputation Eliminate unnecessary abstraction structure 4c. Cache expensive results But can cache coherency be maintained? 4d. Compute lazily Delay expensive operations Bruegge/Software 15-413 Software Engineering Fall 1999 45

4a. Add Redundant Associations More generally Replace bidirectional by unidirectional Replace many-many by 1-many Replace 1-many by 1-1 Add additional associations Cache When to do this? What is the frequency of traversal? What is the relative cost of traversal and the operation performed? Can search be replaced by indexing? E.g., order or hash objects Can indexing be replaced by direct reference? E.g., cache references Bruegge/Software 15-413 Software Engineering Fall 1999 46

4b. Collapse Objects Can this association be an attribute? Can this object be an attribute of another object? Object design choices: Implement entity as embedded attribute Implement entity as separate class with associations to other classes Associations More flexible than attributes Can introduce unnecessary indirection Person Person SSN:String SSN ID:String Bruegge/Software 15-413 Software Engineering Fall 1999 47

4c. Cache Expensive Results Example: How to deal with disconnection in distributed systems? Store derived attributes Example: Define new classes to store information locally Database cache Issues: Derived attributes must be updated when base values change. Cache coherency Storage costs can increase Approaches to the update problem: Periodic computation Deliberately recompute at intervals (inexact) Explicit linking Modified MVC. Active value. Consistency check. Bruegge/Software 15-413 Software Engineering Fall 1999 48

4d. Delay Complex Computations Image filename:string data:byte[] width() height() paint() Image filename:string width() height() paint() Avoid calculating results Deliver proxies instead The essence of lazy computation Drive computation by demand ImageProxy filename:string width() height() paint() image 1 0..1 RealImage data:byte[] width() height() paint() Bruegge/Software 15-413 Software Engineering Fall 1999 49

The Object Design Document (ODD), 1 Object design document Similar to RAD +... + Additions to object, functional and dynamic models (from solution domain) + Navigational map for object model + Javadoc documentation for all classes Bruegge/Software 15-413 Software Engineering Fall 1999 50

ODD Conventions Each subsystem in a system provides a service Describe 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 (where appropriate) Post: Postcondition describing important state after the execution of the operation (where appropriate) Use JavaDoc for the specification of service operations. Bruegge/Software 15-413 Software Engineering Fall 1999 51

The Object Design Document (ODD), 2 ODD Management issues Update the RAD models in the RAD? Should the ODD be a separate document? Target audience for these documents Customer? Developer? Remote team? If time is short: Focus on the Navigational Map and Javadoc documentation Example of acceptable ODD: [ to be provided ] Bruegge/Software 15-413 Software Engineering Fall 1999 52

Packaging Package design into discrete physical units that can be edited, compiled, linked, reused: Ideally one package per subsystem But: system decomposition might not favor implementation. Design principles Minimize coupling: Client-supplier relationships Limit number of parameters Avoid global data Maximize cohesiveness: Tights associations imply same package Consider the number of interface objects offered Interface object : Denotes a service or API For requirements analysis, system/object design. Java interface: Implements an interface object, or not. Bruegge/Software 15-413 Software Engineering Fall 1999 53