Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Object Design  Object design  Detail requirements.

Slides:



Advertisements
Similar presentations
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Software Engineering September 12, 2001 Capturing.
Advertisements

Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Art for Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
CEN Ninth Lecture Introduction to Software Engineering (CEN-4010) Instructor: Masoud Sadjadi Object Design.
Inheritance Inheritance Reserved word protected Reserved word super
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 9, Object Design: Specifying Interfaces.
Object Design: Specifying Interfaces Chapter 9. 2 Object Design  Object design is the process of adding details to the requirements analysis and making.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Chapter 9: Object Design: Specifying Interfaces
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
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.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Art for Chapter 9, Testing.
Chapter 7, Object Design.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Fall 2007CS 2251 Software Engineering Intro. Fall 2007CS 2252 Topics Software challenge Life-cycle models Design Issues Documentation Abstraction.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
JavaDoc COMP 302. JavaDoc javadoc: The program to generate java code documentation. Input: Java source files (.java)  Individual source files  Root.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns I.
Computer Science 340 Software Design & Testing Design By Contract.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
CSC 212 Object-Oriented Programming and Java Part 1.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Software Design Chapter 1. Chapter Objectives  To become familiar with the software challenge and the software life cycle  To understand.
Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Utilities (Part 2) Implementing static features 1.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
OO as a language for acm l OO phrase l Mental model of key concepts.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Few comments about midterm I graded very lightly.
Javadoc Dwight Deugo Nesa Matic
JavaDoc and Contracts Spring Documenting Contracts with JavaDoc Contract model for methods Preconditions Postconditions JavaDoc Industry standard.
Object Oriented Programming
1  lecture slides online
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Why is Design so Difficult? Analysis: Focuses on the application domain Design: Focuses on the solution domain –The solution domain is changing very rapidly.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Bernd Bruegge and Allen Dutoit Requirements Process The requirements process consists of two activities: Requirements Elicitation: Definition of the system.
Chapter 8 Object Design: Reuse and Patterns 1.
Inheritance and Polymorphism
Chapter 9, Object Design: Specifying Interfaces
Introduction to Software Engineering (CEN-4010)
Chapter 8, Object Design: Reuse and Patterns
Defining Classes and Methods
JavaDoc and Contracts Fall 2008.
Chapter 8, Object Design: Reuse and Patterns
Chapter 8, Object Design: Reuse and Patterns I
Computer Science 340 Software Design & Testing
Presentation transcript:

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Object Design  Object design  Detail requirements analysis & make implementation decisions  Iterate on placement of operations in the object model  The basis of implementation  Designer implements model to minimize execution time, memory, & other cost measures.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 2 Object Design: Closing the Gap Custom objects Application objects Off-the-shelf components Solution objects System Problem Machine System design gap (2) Object design gap (3) Requirements gap (1)

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3 Object Design Issues  Full definition of associations  Full definition of classes  Choice of algorithms & data structures  Detect classes that are independent of application- domain (e.g., cache)  Optimization  Increase inheritance

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4 Object Design Activities 1. Service specification  Describe precisely each class interface 2. Component selection  Identify off-the-shelf components 3. Object model restructuring  Improve object design’s understandability & reusability 4. Object model optimization  Improve object design with respect to performance criteria  E.g., response time &memory utilization.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5 Service Specification  Requirements analysis  Identify attributes & operations without types or parameters.  Object design  Specify visibility  Specify type signature  Specify contracts  pre & post conditions.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6 Add Visibility UML defines 3 levels of visibility:  Private  Attribute can be accessed only by the class in which it is defined.  Operation can be invoked only by the class in which it is defined.  Attributes & operations cannot be accessed by subclasses.  Protected  Same as Private access + any extension of the class.  Public  Attribute or operation can be accessed by any class.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 7 Information Hiding Heuristics  Apply “Need to know” principle.  The less an operation knows  the less likely it is affected by a change in another class  the less likely a change affects another class.  Information hiding vs efficiency  Possible that efficiency is not lost due to smart compilation.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8 Information Hiding Design Principles  Book says: All data members are private.  Never use package or protected?  This may be extreme or purist.  Book says: Do not apply an operation to the result of another operation.  Write a new operation that combines the 2 operations.  This seems to me to be a bad idea: makes for entangled methods.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 9 Add Type Signature Information Hashtable +put() +get() +remove() +containsKey() +size() -numElements:int BEFORE AFTER

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 10 Contracts  Class definer & client share assumptions via a contract.  Contracts include 3 types of constraints:  Invariant  A predicate that is true for all instances of the class.  A constraint associated with classes or interfaces.  Precondition  A predicate that must be true before a specific operation is invoked.  Typically, it involves constraints on arguments or the object’s state.  Postcondition  A predicate that must be true after an operation is invoked.  Typically, it involves constraints on modified arguments or the object’s state.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 11 Expressing constraints in UML  OCL (Object Constraint Language)  OCL: constraints on [groups of] model element[s].  A constraint is an OCL expression returning true or false.  Not a procedural language (no control flow).  OCL expressions for Hashtable put():  Invariant  context Hashtable inv: numElements >= 0  Precondition  context Hashtable::put(key, entry) pre:!containsKey(key)  Post-condition  context Hashtable::put(key, entry) post: containsKey(key) and get(key) = entry

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12 Expressing Constraints in UML  A constraint also can be depicted as a note attached to the UML element. HashTable put(key,entry:Object) get(key):Object remove(key:Object) containsKey(key:Object):boolean > numElements >= 0 > !containsKey(key) > containsKey(key) > get(key) == entry size():int numElements:int

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 13 Object Design Activities 1. Service specification  Describe precisely each class interface 2. Component selection  Identify off-the-shelf components 3. Object model restructuring  Improve object design’s understandability & reusability 4. Object model optimization  Improve object design with respect to performance criteria  E.g., response time &memory utilization.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 14 Component Selection  Select existing off-the-shelf libraries of  Classes (e.g., JFC)  Frameworks (e.g., Java Mail)  Components (e.g., An EJB)  Adjust the class libraries, framework, or components  Adjust the API, if you have the source code.  Use an adapter or bridge pattern, if you don’t.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 15 Object Design Activities 1. Service specification  Describe precisely each class interface 2. Component selection  Identify off-the-shelf components 3. Object model restructuring  Improve object design’s understandability & reusability 4. Object model optimization  Improve object design with respect to performance criteria  E.g., response time &memory utilization.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 16 Restructuring Activities  Revise inheritance to remove implementation dependencies  E.g., Look & Feel  Factor out common aspects of groups of classes  Overload to create abstract class from several concrete classes.  Abstract classes increase  Modularity  Extensibility  Reusability

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 17 Implement Associations  Be as uniform as possible  1-to-1 association  Role names are attributes  1-to-many association  Translate to Vector

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 18 1-to-Many Association LayerLayerElement 1* LayerLayerElement -containedIn:Layer-layerElements:Set +elements() +addElement(le) +getLayer() +setLayer(l) +removeElement(le) Object design model beforetransformation Object design model after transformation

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 19 Object Design Activities 1. Service specification  Describe precisely each class interface 2. Component selection  Identify off-the-shelf components 3. Object model restructuring  Improve object design’s understandability & reusability 4. Object model optimization  Improve object design with respect to performance criteria  E.g., response time &memory utilization.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 20 Design Optimizations  The requirements analysis model may be too inefficient.  Strike a balance between efficiency & clarity.  Optimization makes your model more obscure  Optimization activities during object design: 1.Turn classes into attributes 2. Cache derived attributes to omit re-computation

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 21 Optimization: Collapse Classes Person SocialSecurity ID:String Person SSN:String

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 22 To Collapse or not to Collapse?  Collapse a class into attributes when the only operations defined on the attributes are:  set()  get().

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 23 Design Optimizations …  Cache derived attributes  Derived attributes must be updated when base attribute values change.  Explicit code  Base attribute changer re-computes derived attributes.  Event notification  Objects that must re-derive attribute register interest in changes.  Base attribute notifies objects when it changes.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 24 Optimize: Lazy Evaluation (Proxy Pattern) Image filename:String width() height() paint() Image filename:String width() height() paint() RealImage width() height() paint() data:byte[] ImageProxy filename:String width() height() paint() image Image may never be displayed Attributes may change more frequently than need to display

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 25 The Object Design Document (ODD)  Independent ODD  Redundant with RAD  consistency problem.  ODD as supplement to RAD  An optional more detailed view  Ok, if there is a CASE tool to support this.  Javadoc as an ODD.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 26 ODD Conventions  Each subsystem provides a service (interface)  The operations provided by the subsystem  Specify a service operation as  Signature  Operation name, fully typed parameter list, & return type  Abstract: Describes the operation  Pre: Precondition for invoking the operation  Post: Postcondition describing subsystem state after the operation  Use JavaDoc to specify services  Treat subsystems simply as a Java interfaces.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 27 JavaDoc  A doc comment consists of characters between /** & */  When JavaDoc parses a doc comment, leading white space & ‘*’ characters on each line are discarded.  Doc comments may include HTML tags  Example of a doc comment: /** * This is a doc comment */  One expects an XML generalization of this. Doclets.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 28 Java Doc …  Doc comments are recognized only when placed immediately before class, interface, constructor, method, or field declarations.  When using HTML tags, do not use heading tags  E.g., and  It causes a parse error.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 29 Class & Interface Doc name-text  Creates an “Author” version-text  Creates a “Version” classname  Creates a hyperlink “See Also since-text  Adds a “Since” entry.  Usually specifies that a feature or change exists since the release number specified in the deprecated-text  Adds a comment that this method can no longer be used. Convention is to describe method that serves as replacement  Replaced by setBounds(int, int, int, int).

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 30 Constructor & Method Doc Tags  Can @param parameter-name description Adds a parameter to the "Parameters" section. The description may be continued on the next description Adds a "Returns" section, which contains the description of the return fully-qualified-class-name description Adds a "Throws" section that has the name of the exception that may be thrown by the method. The exception is linked to its class classname Adds a hyperlink "See Also" entry to the method.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 31 Example of a Class Doc Comment /** * A class representing a window on the screen. * For example: * * Window win = new Window(parent); * win.show(); * Sami Shaio java.awt.BaseWindow java.awt.Button */ class Window extends BaseWindow { … }

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 32 Example of a Method Doc Comment /** * Returns the character at the specified index. An index * ranges from 0 to length() - 1. * index the index of the desired character. the desired character. StringIndexOutOfRangeException * if the index is not in the range 0 * to length()-1. java.lang.Character#charValue() */ public char charAt(int index) {... }

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 33 Example of a Field Doc Comment  A field comment can contain tags /** * The X-coordinate of the window. * window#1 */ int x = ;

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 34 Example: Specifying a Service in Java /** Office is a physical structure in a building. It is possible to create an office; add an occupant; get the name of the office */ public interface Office { /** Adds an occupant to the office NAME name is a nonempty string */ public void addOccupant(string name); Returns the name of the office. Requires that Office has been initialized with a name */ public string getName(); }

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 35 Implementation of Application Domain Classes  New objects are often needed during object design:  Use of Design patterns lead to new classes  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: The EraseArea() operation offered by a drawing program.  Conceptually very simple  Implementation  Area represented by pixels  Repair () cleans up objects partially covered by the erased area  Redraw() draws objects uncovered by the erasure  Draw() erases pixels in background color not covered by other objects

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 36 Summary  Object design  add details to the requirements analysis  make implementation decisions  Object design includes 1. Service specification 2. Component selection 3. Object model restructuring 4. Object model optimization  Use tools such as JavaDoc for the ODD