Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Similar documents
On to Object-oriented Design

On to Object-oriented Design

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

17. GRASP: Designing Objects with Responsibilities

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

Responsibilities. Using several specific design principles to guide OO design decisions.

Information Expert (or Expert)

COMP 6471 Software Design Methodologies

GRASP: Patterns for. chapter18

Operations Contracts and Preliminaries on Design

Domain Model and Domain Modeling

CTIS 359 Principles of Software Engineering SOFTWARE DESIGN OO(A)D

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

Assigning Responsibilities by Larman

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Object Analysis & Design in the textbook. Introduction to GRASP: Assigning Responsibilities to Objects. Responsibility-Driven Design

Principles of Software Construction: Objects, Design and Concurrency. Object-Oriented Design: Assigning Responsibilities.

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

Domain Modeling- 2. Generalization

Produced by. Agile Software Development. Eamonn de Leastar

COMP 6471 Software Design Methodologies

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Goal: build an object-oriented model of the realworld system (or imaginary world) Slicing the soup: OOA vs. OOD

References: Applying UML and patterns Craig Larman

CSSE 374: Logical Architecture. Shawn Bohner Office: Moench Room F212 Phone: (812)

OO Design2. Design Artifacts

Logical Architecture & Design Preliminaries

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

Single Responsibility Principle (SRP)

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

Constantinos Constantinides Computer Science and Software Engineering Concordia University Montreal, Canada

Mapping Designs to Code

Object-Oriented Design

Software Modeling & Analysis

Domain Modeling. CSSE 574: Week 1, Part 3. Steve Chenoweth Phone: Office (812) Cell (937)

GRASP Design Patterns A.A. 2018/2019

Software Engineering Design & Construction

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Outline. Software Rots

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Software Engineering Design & Construction

What is a Model? Copyright hebley & Associates

GRASP ing at the First 5 Patterns Principles CSSE 574: Session 3, Part 4

Object-Oriented Design

Object-Oriented Design

Modeling Dynamic Behavior

From designing to coding

Domain Modeling: Associations and Attributes

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt

Topic : Object Oriented Design Principles

Modeling Dynamic Behavior

Introduction to Design Patterns

Agile Software Development

Software Design and Analysis CSCI 2040

Introduction to Design Patterns

System Sequence Diagrams. Based on Craig Larman, Chapter 10 and Anuradha Dharani s notes

Designing for Visibility & Mapping to Code CSSE 574: Session 4, Part 3

Creating Class Definitions from Design Class Diagrams: public class SalesLineItem // Java { private int quantity;

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

Chapter 1: Principles of Programming and Software Engineering

SE203b: OO Design for Software Engineers. Office: TEB349, Ext

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

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING CS2353-OBJECT ORIENTED ANALYSIS AND DESIGN. Unit-I. Introduction to OOAD

Tecniche di Progettazione: Design Patterns

CS 2340 Objects and Design

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

OBJECT ORIENTED ANALYSIS AND DESIGN SYLLABUS

Object-Oriented Systems Analysis and Design Using UML

Software Engineering Design & Construction

CS6502-OBJECT ORIENTED ANALYSIS AND DESIGN Two Marks Question with Answers Unit-I Introduction to OOAD

Chapter 1: Programming Principles

Lecture Chapter 2 Software Development

Agile Principles, Patterns, and Practices in C#

Lecture Notes UML UNIT-II. Subject: OOAD Semester: 8TH Course No: CSE-802

Why Use Object-Oriented Programming in the First Place?

Review of Basic Software Design Concepts. Fethi Rabhi SENG 2021

Ingegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles

Architectural Models. Section Outline. What is an architectural design? Architecture Types. Example Logical Architecture. Example Deployment Diagram

INTERNAL ASSESSMENT TEST III Answer Schema

Design Patterns and Frameworks 1) Introduction

ROEVER ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY CS2353-OBJECT ORIENTED ANALYSIS AND DESIGN. Unit-I. Introduction to OOAD

Patterns and Testing

Object-Oriented Functional Analysis and Design for POS Example

Chapter 3: Object Oriented Design

Software Engineering

Object-Oriented Design

Software Design. Software design is a blueprint or a plan for a computerbased solution for system

4 Software models. often more than what people can handle not necessary to know all details at all times

Principles of Software Construction: Objects, Design, and Concurrency

21) Functional and Modular Design

Design Engineering. Overview

The Design Patterns Matrix From Analysis to Implementation

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles

OBJECT ORIENTED DESIGN with the Unified Process. Use Case Realization

GRASP 2. CSC 440: Software Engineering Slide #1

21) Functional and Modular Design

Assigning Responsibilities

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

Transcription:

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of Computer Science Technische Universität Darmstadt

Dr. Michael Eichberg Fachgebiet Software Engineering Department of Computer Science Technische Universität Darmstadt Introduction to Software Engineering On to Object-oriented Design

Object-oriented Design 3 Object-oriented Design A popular way of thinking about the design of software objects and also large scale components is in terms of responsibilities, roles and collaborations.

Object-oriented Design We are currently entering the design phase. Object-oriented Design 4 Current results The result of a first iteration in the development process: a simple domain (analysis / conceptual) model does exist descriptions of use-cases (user stories) which are under development in the current iterative step we do have a system sequence diagram Next steps Build interaction diagrams for system operations of the use-cases at hand by applying guidelines and principles for assigning responsibilities

Object-oriented Design 5 Sales LineItem quantity Contained-in 1..* Records-sale-of 0..1 1 Item * loop :Cashier :System makenewsale [more items] enteritem(itemid, quantity) description, total Sale date time 1 0..1 1 Store address name Stocked-in Paid-by Captured-on! endsale makepayment (amount) Payment amount 1 Register Houses Which class / object should have which responsibility?

System Events and System Operations Object-oriented Design 6 System operations are the operations that the system as a black box component offers in its public interface. These are high-level operations triggered by an external input event / system event generated by an external actor. During system behavior analysis, system operations are assigned to a conceptual class System. Repetition

The system operations are shown in the system sequence diagram (SSD). Object-oriented Design 7 To provide more analysis detail on the effect of the system operations implied use cases, (System) Operation Contracts may be considered :Cashier makenewsale :System loop [more items] enteritem(itemid, quantity) description, total endsale makepayment (amount) Repetition

Operation Contract Template Object-oriented Design 8 Operation: Name of the operation and parameters. Cross References: Use cases this operation can occur with. Preconditions: Noteworthy / non-trivial assumptions about the system or objects in the domain model before execution of the operation. Postconditions: The state of the objects in the domain model after completion of the operation. Domain model state changes include:!instances created,!associations formed or broken,!attributes changed. [Postconditions should be stated in the past tense.] Helpful when assigning responsibilities to classes.

Operation Contract for enteritem() Object-oriented Design 9 Operation: enteritem(itemid: ItemId, quantity: Integer) Cross References: Use Cases: Process Sale Preconditions: There is a sale underway. Postconditions:!A SalesLineItem instance (SLI) was created. (instance creation)!sli was associated with the current Sale. (association formed)!sli was associated with a ProductDescription, based on itemid match. (association formed)

Interaction Diagrams for System Operations Object-oriented Design 10 Create a separate diagram for each system operation in the current development cycle Use the system operation, e.g., enteritem(), as starting message If a diagram gets complex, split it into smaller diagrams Distribute responsibilities among classes: from the conceptual model and may be others added during object design The classes will collaborate for performing the system operation. based on the description of the behavior of system operations

Responsibility for System Operations Object-oriented Design 11 During system behavior analysis (e.g. of the POS system), system operations are assigned to a conceptual class (e.g. System) Does not imply that there will be a class System in the design. A controller class is assigned to perform the system operations System endsale() enteritem() makepayment()

Responsibility for System Operations Object-oriented Design 12 During system behavior analysis (e.g. of the POS system), system operations are assigned to a conceptual class (e.g. System) Who should be responsible for handling system operations? What first object beyond the UI layer receives and coordinates a system operation? Does not imply that there will be a class System in the design. A controller class is assigned to perform the system operations System endsale() enteritem() makepayment()

Responsibility for System Operations Object-oriented Design 13 During system behavior analysis (e.g. of the POS system), system operations are assigned to a conceptual class (e.g. System) This does not imply that there will be a class System in the design. A controller class is assigned to perform the system operations The system operations become the starting messages entering the controllers for domain layer interaction diagrams.

Dr. Michael Eichberg Fachgebiet Software Engineering Department of Computer Science Technische Universität Darmstadt Introduction to Software Engineering Foundations of Object-oriented Design

Object-oriented Design - Responsibility 15 Responsibility UML Definition Responsibility: a contract or obligation of a classifier.

Object-oriented Design - Responsibility 16 Responsibility R. Martin Each responsibility is an axis of change. When the requirements change, a change will manifest through a change in responsibility amongst the classes. If a class has multiple responsibilities, it has multiple reasons to change.

Object-oriented Design - Responsibility 17 Responsibility Assigning to classes is one of the most important activities during the design. Patterns, idioms, principles etc. help in assigning the responsibilities. US Department of Defense

Object-oriented Design - Responsibility 18 In Responsibility-driven Design (RDD) we think of software objects as having responsibilities. The responsibilities are assigned to classes of objects during object-design.

Responsibilities are related to the obligations or behavior of an object in terms of its role. We can distinguish two basic types of responsibilities. Doing responsibilities: Doing something itself E.g. creating an object or doing a calculation. Initiating action in other objects Object-oriented Design - Responsibility 19 Controlling and coordinating activities in other objects Example: a Sale object is responsible for creating SalesLineItem objects Knowing responsibilities: Knowing about private encapsulated data Knowing about related objects Knowing about things it can derive or calculate Example: a Sale is responsible for knowing its total

Responsibilities are assigned to objects by using methods of classes to implement them. Object-oriented Design - Responsibility 20 To implement a responsibility methods act alone or collaborate with other methods (of other objects): 1 method in 1 object, } depending on the 5 methods in 1 object, granularity of the 50 methods across 10 objects responsibility A responsibility is not the same thing as a method.

Responsibilities are assigned to objects by using methods of classes to implement them. Object-oriented Design - Responsibility 21 Examples: Providing access to data bases may involve dozens of classes Print a sale may involve only a single or a few methods Assigning responsibilities to classes is one of the most important activities during the design. Patterns, idioms, principles etc. help in assigning the responsibilities. A responsibility is not the same thing as a method.

Object-oriented Design - Responsibility 22????? How does one determine the assignment of responsibilities to various objects?????

Object-oriented Design - Responsibility 23 How does one determine the assignment of responsibilities to various objects? There is a great variability in responsibility assignment : Hence, good and poor designs, beautiful and ugly designs, efficient and inefficient designs. Poor choices lead to systems which are fragile and hard to maintain, understand, reuse, or extend! Main topic until the end of this lecture series.

Coupling Object-oriented Design - Coupling 24 Coupling measures the strength of dependence between classes and packages. Class C1 is coupled to class C2 if C1 requires C2 directly or indirectly. A class that depends on 2 other classes has a lower coupling than a class that depends on 8 other classes Coupling is an evaluative principle!

Common Forms of Coupling in Java Object-oriented Design - Coupling 25 Type X has an attribute that refers to a type Y instance or type Y itself A type X object calls methods of a type Y object Type X has a method that references an instance of type Y (E.g. by means of a parameter, local variable, return type, ) Type X is a subtype of type Y....

Coupling Object-oriented Design - Coupling 26 High Coupling A class with high coupling is undesirable, because... changes in related classes may force local changes harder to understand in isolation harder to reuse because its use requires the inclusion of all classes it is dependent upon...

Coupling Object-oriented Design - Coupling 27... Low Coupling Low coupling supports design of relatively independent, hence more reusable, classes Generic classes, with high probability for reuse, should have especially low coupling Very little or no coupling at all is also not desirable Central metaphor of OO: a system of connected objects that communicate via messages Low coupling taken to excess results in active objects that do all the work

Coupling Object-oriented Design - Coupling 28... Low Coupling Low coupling supports design of relatively independent, hence more reusable, classes Generic classes, with high probability for reuse, should have especially low coupling High coupling to stable elements and to pervasive elements is seldom a problem. Very little or no coupling at all is also not desirable Central metaphor of OO: a system of connected objects that communicate via messages Low coupling taken to excess results in active objects that do all the work

Coupling Object-oriented Design - Coupling 29... Low Coupling Low coupling supports design of relatively independent, hence more reusable, classes Beware: the quest for low coupling to achieve reusability in a future (mythical!) project may lead to needless complexity and increased project cost. Generic classes, with high probability for reuse, should have especially low coupling Very little or no coupling at all is also not desirable Central metaphor of OO: a system of connected objects that communicate via messages Low coupling taken to excess results in active objects that do all the work

Cohesion Object-oriented Design - Cohesion 30 Cohesion measures the strength of the relationship amongst elements of a class All operations and data within a class should naturally belong to the concept that the class models Cohesion is an evaluative principle!

Types of Cohesion Object-oriented Design - Cohesion 31 Coincidental No meaningful relationship amongst elements of a class. Logical cohesion (functional cohesion) Elements of a class perform one kind of a logical function. E.g., interfacing with the POST hardware. Temporal cohesion All elements of a class are executed together.

Object-oriented Design - Cohesion 32 Responsibility To keep design complexity manageable, assign responsibilities while maintaining high cohesion. Cohesion

Low Cohesion Object-oriented Design - Cohesion 33 Classes with low cohesion are undesirable, because they are... hard to comprehend, hard to reuse hard to maintain - easily affected by change Classes with low cohesion... often represent a very large-grain abstraction have taken responsibility that should have been delegated to other objects Classes with high cohesion can often be described by a simple sentence.

Low Cohesion Object-oriented Design - Cohesion 34 Classes with low cohesion are undesirable, because they are... hard to comprehend, hard to reuse hard to maintain - easily affected by change Classes with low cohesion... often represent a very large-grain abstraction have taken responsibility that should have been delegated to other objects Classes with high cohesion can often be described by a simple sentence.

Object-oriented Design 35 Design needs principles.

Object-oriented Design 36 The Single Responsibility Principle A class should have only one reason to change.! I.e. a responsibility is primarily a reason for change. Agile Software Development; Robert C. Martin; Prentice Hall, 2003

Example: a Rectangle Class The Single Responsibility Principle Object-oriented Design 37 Computational Geometry Application Rectangle +draw() +area() : double Graphical Application GUI Does the Rectangle class have? a single responsibility or does it have multiple responsibilities

Example: a Rectangle Class The Single Responsibility Principle Object-oriented Design 38 Computational Geometry Application Rectangle +draw() +area() : double Graphical Application GUI The Rectangle class has multiple responsibilities: Calculating the size of a rectangle; a mathematical model To render a rectangle on the screen; a GUI related functionality Do you see any problems?

Example: a Rectangle Class The Single Responsibility Principle Object-oriented Design 39 Computational Geometry Application Rectangle +draw() +area() : double Graphical Application GUI Problems due to having multiple responsibilities: Reuse of the Rectangle class (e.g. in a math package) is hindered due to the dependency on the GUI package (GUI classes have to be deployed along with the Rectangle class) A change in the Graphical Application that results in a change of Rectangle requires that we retest and redeploy the Rectangle class in the context of the Computational Geometry Application

Example: Rectangle classes with single responsibilities The Single Responsibility Principle Object-oriented Design 40 Computational Geometry Application Graphical Application Geometric Rectangle +area() : double +draw() Rectangle GUI The solution is to separate the functionality for drawing a rectangle and the functionality for doing calculations are separated. Coupling? Cohesion?

Example: Handling Persistence The Single Responsibility Principle Object-oriented Design 41 Persistence Subsystem Employee +CalculatePay() +Store(...) Do we need to change the Employee class?

Example: Handling Persistence The Single Responsibility Principle Object-oriented Design 42 Persistence Subsystem Employee +CalculatePay() +Store(...) Two responsibilities: Business functionality Persistence related functionality Do we need to change the Employee class?

Orthogonality Object-oriented Design Two or more things are orthogonal if changes in one do not affect any of the others; e.g. if a change to the database code does not affect your GUI code, both are said to be orthogonal. 43 z y if z changes, x and y remain unchanged x Source: Author: The Pragmatic Programmer, Addison-Wesley, 2000 Andrew Hunt, David Thomas