Principles of Software Construction: Objects, Design, and Concurrency

Similar documents
A formal design process, part 2

Principles of Software Construction: Objects, Design, and Concurrency

Principles of Software Construction: Objects, Design, and Concurrency

Principles of So3ware Construc9on. A formal design process, part 2

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

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

CS246 Software Abstraction and Specification Final Examination

Assigning Responsibilities

Principles of Software Construction: Objects, Design, and Concurrency. Part 1: Design for reuse. Design patterns for reuse

Äriprotsesside modelleerimine ja automatiseerimine Loeng 7 Valdkonna mudel

Introduction to concurrency and GUIs

17. GRASP: Designing Objects with Responsibilities

Chapter 1: Programming Principles

Principles of Software Construction: Objects, Design, and Concurrency. Part 1: Designing Classes. Design for Reuse School of Computer Science

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

Object Oriented Programming

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

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Chapter 1: Principles of Programming and Software Engineering

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

Department of Computer Science Undergraduate Events

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

Object Oriented Software Development CIS Today: Object Oriented Analysis

Principles of Software Construction: Objects, Design, and Concurrency. The Perils of Concurrency Can't live with it. Can't live without it.

CSSE 374: GRASP ing at the First Five Patterns Principles. Shawn Bohner Office: Moench Room F212 Phone: (812)

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

COMP 6471 Software Design Methodologies

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

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

GRASP: Patterns for. chapter18

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

An Introduction to Patterns

CS112 Lecture: Defining Instantiable Classes

Patterns and Testing

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100

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

Object-Oriented Design

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

Principles of Software Construction: Objects, Design, and Concurrency

Charlie Garrod Michael Hilton

Software Design Heuristics

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

Object Oriented Programming and Design in Java. Session 10 Instructor: Bert Huang

Domain Model and Domain Modeling

Principles of Software Construction: Objects, Design, and Concurrency. The Perils of Concurrency Can't live with it. Cant live without it.

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

SHRI ANGALAMMAN COLLEGE OF ENGINEERING & TECHNOLOGY (An ISO 9001:2008 Certified Institution) SIRUGANOOR,TRICHY

Principles of Software Construction: Objects, Design and Concurrency. Introduction to Design. toad

Object-Oriented Design. Module UFC016QM. and Programming. Objects and Classes. O-O Design Unit 2: Faculty of Computing, Engineering

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Lecture 5 STRUCTURED ANALYSIS. PB007 So(ware Engineering I Faculty of Informa:cs, Masaryk University Fall Bühnová, Sochor, Ráček

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

CSE 70 Final Exam Fall 2009

Josh Bloch Charlie Garrod Darya Melicher

Object-Oriented Programming Paradigm

Information Expert (or Expert)

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

CHAPTER 9 DESIGN ENGINEERING. Overview

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

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

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

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

06. Analysis Modeling

Object-oriented Programming Project

OBJECT ORİENTATİON ENCAPSULATİON

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

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

VALLIAMMAI ENGINEERING COLLEGE

Lecture 13 Introduction to Software Architecture

Chapter 8: Class and Method Design

COURSE 2 DESIGN PATTERNS

Software Modeling & Analysis

LECTURE 3: SOFTWARE DESIGN. Software Engineering Mike Wooldridge

Object-Oriented and Classical Software Engineering

Software Design and Analysis CSCI 2040

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD TM : ,

Object Design II: Design Patterns

Agile Model-Driven Development with UML 2.0 SCOTT W. AM BLER. Foreword by Randy Miller UNIFIED 1420 MODELING LANGUAGE. gile 1.

Topics in Object-Oriented Design Patterns

Release Date: September, 2015 Updates:

user.book Page 45 Friday, April 8, :05 AM Part 2 BASIC STRUCTURAL MODELING

COMP 6471 Software Design Methodologies

Software Engineering with Objects and Components Open Issues and Course Summary

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

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

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

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

ArchiMate 2.0. Structural Concepts Behavioral Concepts Informational Concepts. Business. Application. Technology

University of Calgary Department of Electrical and Computer Engineering. SENG : Object Oriented Analysis and Design Behrouz Homayoun Far

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

Chapter : Analysis Modeling

CSCU9T4: Managing Information

CS6502- OBJECT ORIENTED ANALYSIS AND DESIGN UNIT I

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

Principles of Software Construction: Objects, Design, and Concurrency

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

Transcription:

Principles of Software Construction: Objects, Design, and Concurrency Designing (sub-) systems Responsibility assignment Charlie Garrod Michael Hilton School of Computer Science 1

Administrivia Reading for Today: UML and Patterns Chapter 14, 15, and 16 Midterm exam next Thursday (September 28 th ) Exam review session: Hamerschlag Hall B103 Wed 7-9pm Practice Exam posted on Piazza Muddiest Point Feedback 2

Homework 4 Three parts, part A due Oct 5 th Design review meeting next week 3

REVIEW: Sequence and communication diagrams 4

Our path toward a more formal design process Problem Space Solution Space Domain Model Object Model Real-world concepts Requirements, concepts Relationships among concepts Solving a problem Building a vocabulary System implementation Classes, objects References among objects and inheritance hierarchies Computing a result Finding a solution 5

Artifacts of our design process Model / diagram the problem, define objects Domain model (a.k.a. conceptual model) Define system behaviors System sequence diagram System behavioral contracts Assign object responsibilities, define interactions Object interaction diagrams Model / diagram a potential solution Object model Understanding the problem Defining a solution 6

Building a domain model for a library system A public library typically stores a collection of books, movies, or other library items available to be borrowed by people living in a community. Each library member typically has a library account and a library card with the account s ID number, which she can use to identify herself to the library. A member s library account records which items the member has borrowed and the due date for each borrowed item. Each type of item has a default rental period, which determines the item s due date when the item is borrowed. If a member returns an item after the item s due date, the member owes a late fee specific for that item, an amount of money recorded in the member s library account. 7

One domain model for the library system 8

Notes on the library domain model All concepts are accessible to a non-programmer The UML is somewhat informal Relationships are often described with words Real-world "is-a" relationships are appropriate for a domain model Real-word abstractions are appropriate for a domain model Iteration is important This example is a first draft. Some terms (e.g. Item vs. LibraryItem, Account vs. LibraryAccount) would likely be revised in a real design. Aggregate types are usually modeled as classes Primitive types (numbers, strings) are usually modeled as attributes 9

Build a domain model for Monopoly 10

Build a domain model for Monopoly Monopoly is a game in which each player has a piece that moves around a game board, with the piece s change in location determined by rolling a pair of dice. The game board consists of a set of properties (initially owned by a bank) that may be purchased by the players. When a piece lands on a property that is not owned, the player may use money to buy the property from the bank for that property s price. If a player lands on a property she already owns, she may build houses and hotels on the property; each house and hotel costs some price specific for the property. When a player s piece lands on a property owned by another player, the owner collects money (rent) from the player whose piece landed on the property; the rent depends on the number of houses and hotels built on the property. The game is played until only one remaining player has money and property, with all the other players being bankrupt. 11

Understanding system behavior with sequence diagrams A system sequence diagram is a model that shows, for one scenario of use, the sequence of events that occur on the system s boundary Design goal: Identify and define the interface of the system Two components: A user and the overall system 12

Understanding system behavior with sequence diagrams A system sequence diagram is a model that shows, for one scenario of use, the sequence of events that occur on the system s boundary Design goal: Identify and define the interface of the system Two components: A user and the overall system Input: Domain description and one use case Output: A sequence diagram of system-level operations Include only domain-level concepts and operations 13

One sequence diagram for the library system Use case scenario: A library member should be able to use her library card to log in at a library system kiosk and borrow a book. After confirming that the member has no unpaid late fees, the library system should determine the book s due date by adding its rental period to the current day, and record the book and its due date as a borrowed item in the member s library account. 14

One sequence diagram for the library system Use case scenario: A library member should be able to use her library card to log in at a library system kiosk and borrow a book. After confirming that the member has no unpaid late fees, the library system should determine the book s due date by adding its rental period to the current day, and record the book and its due date as a borrowed item in the member s library account. 15

Build one system sequence diagram for Monopoly Use case scenario: When a player lands on an unowned property and has enough money to buy the property, she should be able to buy the property for the property s price. The property should no longer be purchasable from the bank by other players, and money should be moved from the player to the bank. 16

Formalize system behavior with behavioral contracts A system behavioral contract describes the pre-conditions and post-conditions for some operation identified in the system sequence diagrams System-level textual specifications, like software specifications 17

A system behavioral contract for the library system Operation: borrow(item) Pre-conditions: Library member has already logged in to the system. Item is not currently borrowed by another member. Post-conditions: Logged-in member's account records the newly-borrowed item, or the member is warned she has an outstanding late fee. The newly-borrowed item contains a future due date, computed as the item's rental period plus the current date. 18

A system behavioral contract for Monopoly Operation: buy(property) Pre-conditions:? Post-conditions:? 19

Distinguishing domain vs. implementation concepts Domain-level concepts: Almost anything with a real-world analogue Implementation-level concepts: Implementation-like method names Programming types Visibility modifiers Helper methods or classes Artifacts of design patterns 20

Summary: Understanding the problem domain Know your tools to build domain-level representations Domain models System sequence diagrams System behavioral contracts Be fast and (sometimes) loose Elide obvious(?) details Iterate, iterate, iterate, Get feedback from domain experts Use only domain-level concepts 21

Artifacts of our design process Model / diagram the problem, define objects Domain model (a.k.a. conceptual model) Define system behaviors System sequence diagram System behavioral contracts Assign object responsibilities, define interactions Object interaction diagrams Model / diagram a potential solution Object model Understanding the problem Defining a solution 22

Object-oriented programming Programming based on structures that contain both data and methods public class Bicycle { private int speed; private final Wheel frontwheel, rearwheel; private final Seat seat; public Bicycle( ) { } public void accelerate() { speed++; } } public int speed() { return speed; } 23

Object-Oriented Design Object-Oriented Design: After identifying your requirements and creating a domain model, then add methods to the software classes, and define the messaging between the objects to fulfill the requirements. But how? How should concepts be implemented by classes? What method belongs where? How should the objects interact? This is a critical, important, and non-trivial task 24

Responsibility in object-oriented programming Data: Private or otherwise encapsulated data Data in closely related objects Methods: Private or otherwise encapsulated operations Object creation, of itself or other objects Initiating actions in other objects Coordinating activities among objects 25

Responsibilities Responsibilities are related to the obligations of an object in terms of its behavior. Two types of responsibilities: knowing doing Doing responsibilities of an object include: doing something itself, such as creating an object or doing a calculation initiating action in other objects controlling and coordinating activities in other objects Knowing responsibilities of an object include: knowing about private encapsulated data knowing about related objects knowing about things it can derive or calculate 26

Using interaction diagrams to assign object responsibility For a given system-level operation, create an object interaction diagram at the implementation-level of abstraction Implementation-level concepts: Implementation-like method names Programming types Helper methods or classes Artifacts of design patterns 27

Example interaction diagram #1 Use case scenario: A library member should be able to use her library card to log in at a library system kiosk and 28

Example interaction diagram #2 Use case scenario: and borrow a book. After confirming that the member has no unpaid late fees, the library system should determine the book s due date by adding its loan period to the current day, and record the book and its due date as a borrowed item in the member s library account. 29

Interaction diagrams help evaluate design alternatives Create two possible interaction diagrams: 1. Solving a cryptarithm, assuming that the cryptarithm class has responsibility for solving itself 2. Solving a cryptarithm, assuming that the main method (or a delegated method or class) has responsibility for solving the cryptarithm 30

Goals, Principles, Guidelines Goals Design Goals Desired quality attributes of software Principles Driven by cost/benefit economics Examples: design for change, understanding, reuse, Design Principles Guidelines for designing software Heuristics Patterns Support one or more design goals Examples: Information hiding, low repr. gap, low coupling, high cohesion, Design Heuristics Rules of thumb for low-level design decisions Promote design principles, and ultimately design goals Example: Creator, Expert, Controller Design Patterns General solutions to recurring design problems Promote design goals, but may add complexity or involve tradeoffs Examples: Decorator, Strategy, Template Method Goals, principles, heuristics, patterns may conflict Use high-level goals of project to resolve X 31

Heuristics for responsibility assignment Controller heuristic Information expert heuristic Creator heuristic Goals Principles Heuristics Patterns 32

The controller heuristic Assign responsibility for all system-level behaviors to a single system-level object that coordinates and delegates work to other objects Also consider specific sub-controllers for complex use-case scenarios Design process: Extract interface from system sequence diagrams Key principles: Low representational gap and high cohesion 33

Information expert heuristic Assign responsibility to the class that has the information needed to fulfill the responsibility Initialization, transformation, and views of private data Creation of closely related or derived objects 34

Responsibility in object-oriented programming Data: Private or otherwise encapsulated data Data in closely related objects Methods: Private or otherwise encapsulated operations Object creation, of itself or other objects Initiating actions in other objects Coordinating activities among objects 35

Information expert heuristic Assign responsibility to the class that has the information needed to fulfill the responsibility Initialization, transformation, and views of private data Creation of closely related or derived objects Design process: Assignment from domain model Key principles: Low representational gap and low coupling 36

Use the information expert heuristic In Homework 3, what object should have the responsibility to solve a cryptarithm? What is the relevant information? 37

Use the information expert heuristic In Homework 3, what object should have the responsibility to solve a cryptarithm? What is the relevant information? Who knows the # of digits (e.g. base 10) in the cryptarithm? Who knows the letters of the cryptarithm? Who can evaluate the cryptarithm expressions to check for equality? 38

Another design principle: Minimize conceptual weight Label the concepts for a proposed object Related to representational gap and cohesion 39

Creator heuristic: Who creates an object Foo? Assign responsibility of creating an object Foo to a class that: Has the data necessary for initializing instances of Foo Contains, aggregates, or records instances of Foo Closely uses or manipulates instances of Foo Design process: Extract from domain model, interaction diagrams Key principles: Low coupling and low representational gap 40

Use the creator heuristic In Homework 3, what object should have the responsibility for creating the permutation generator? 41

Object-level artifacts of this design process Object interaction diagrams add methods to objects Can infer additional data responsibilities Can infer additional data types and architectural patterns Object model aggregates important design decisions Is an implementation guide 42

Creating an object model Extract data, method names, and types from interaction diagrams Include implementation details such as visibilities 43

44

Create an object model for your cryptarithm solver 45

Summary: Object-level interaction diagrams and object model systematically guide the design process Convert domain model, system sequence diagram, and contracts to object-level responsibilities Use heuristics to guide, but not define, design decisions Iterate, iterate, iterate 46