MSO Lecture 3. Wouter Swierstra. September 14, 2015

Similar documents
MSO Analysis & UML. Hans Philippi (based on the course slides of Wouter Swierstra) August 24, Analysis & UML 1 / 56

Software Engineering Prof.N.L.Sarda IIT Bombay. Lecture-11 Data Modelling- ER diagrams, Mapping to relational model (Part -II)

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

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

Object Oriented Software Development CIS Today: Object Oriented Analysis

Object-Oriented Design

Domain Model and Domain Modeling


CSE 403: Software Engineering, Spring courses.cs.washington.edu/courses/cse403/15sp/ UML Class Diagrams. Emina Torlak

Object-Oriented Systems Analysis and Design Using UML

Design and UML Class Diagrams

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

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

MechEng SE3 Lecture 7 Domain Modelling

Software Service Engineering

Object-Oriented and Classical Software Engineering

UML. By Somenath Mukhopadhyay.

CS350 Lecture 2 Requirements Engineering. Doo-Hwan Bae

Äriprotsesside modelleerimine ja automatiseerimine Loeng 7 Valdkonna mudel

SEEM4570 System Design and Implementation Lecture 11 UML

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

22/09/2012 INFO2110. Copyright Warning. Revision of class diagram. Overview. Purpose of class diagram. Generalization Relationship

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

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

OO System Models Static Views

Entity Relationship Modelling

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

Basic Structural Modeling. Copyright Joey Paquet,

SEEM4570 System Design and Implementation. Lecture 10 UML

Practical UML - A Hands-On Introduction for Developers

Class diagrams and architectural design

OBJECT ORİENTATİON ENCAPSULATİON

SketchUp Quick Start For Surveyors

MSO Object Creation Singleton & Object Pool

Data Analysis 1. Chapter 2.1 V3.1. Napier University Dr Gordon Russell

Modeling with UML. (1) Use Case Diagram. (2) Class Diagram. (3) Interaction Diagram. (4) State Diagram

UML class diagrams. Nigel Goddard. School of Informatics University of Edinburgh

CSCU9T4: Managing Information

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

Today s Topic. Lecture 5. What is UML? Why Use UML. UML Diagrams. Introduction to UML. What is UML Why use UML? UML Diagrams

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

Practical UML : A Hands-On Introduction for Developers

OO Techniques & UML Class Diagrams

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

PART A : MULTIPLE CHOICE Circle the letter of the best answer (1 mark each)

Class Diagrams in Analysis

Requirements & Domain Models. Lecture 13: Object Oriented Modelling. Nearly anything can be an object. Object Oriented Analysis

Lecture 8: Use Case -Driven Design. Where UML fits in

Week 4 Tute/Lab Entity-Relationship (ER) Model

Lecture 34 SDLC Phases and UML Diagrams

Database Systems. Overview - important points. Lecture 5. Some introductory information ERD diagrams Normalization Other stuff 08/03/2015

Introduction to Software Engineering. 5. Modeling Objects and Classes

LABORATORY 1 REVISION

UML Fundamental. OutLine. NetFusion Tech. Co., Ltd. Jack Lee. Use-case diagram Class diagram Sequence diagram

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

Principles of Software Construction: Objects, Design, and Concurrency

APPENDIX M INTRODUCTION TO THE UML

Design of Embedded Systems

Object-Oriented Design

CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers

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

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

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

Unified Modeling Language I.

An Introduction to Subtyping

Working with Health IT Systems is available under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported license.

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Introducing the UML Eng. Mohammed T. Abo Alroos

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

System Analysis & design

CS352 Lecture - Data Models

Introduction to UML. Danang Wahyu utomo

Chapter 2: Entity-Relationship Model

BASICS OF BPMN BASIC BPMN SUBSET OKAY, SO WHAT DO I REALLY NEED TO KNOW? CHAPTER 2

Object- Oriented Analysis, Design and Programming

Course "Softwaretechnik" Book Chapter 2 Modeling with UML

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Object Oriented Design. Program Design. Analysis Phase. Part 2. Analysis Design Implementation. Functional Specification

IMS1002/CSE1205 Lectures 1

Computer Science for Engineers

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

THE UNIFIED MODELING LANGUAGE

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Domain-Driven Development with Ontologies and Aspects

Slide 1 Welcome to Fundamentals of Health Workflow Process Analysis and Redesign: Process Mapping: Entity-Relationship Diagrams. This is Lecture e.

Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered.

Darshan Institute of Engineering & Technology for Diploma Studies

Unified Modeling Language (UML)

Chapter 2: The Object-Oriented Design Process

COSC 3351 Software Design. An Introduction to UML (I)

Using Microsoft Word. Tables

Software Engineering Lab Manual

Lecture 7, Part 1: Object Oriented Modelling

Review: Cohesion and Coupling, Mutable, Inheritance Screen Layouts. Object-Oriented Design CRC Cards - UML class diagrams

Why Use Graphs? Test Grade. Time Sleeping (Hrs) Time Sleeping (Hrs) Test Grade

MSO Exam November 7, 2016, 13:30 15:30, Educ-Gamma

What is a Model? Copyright hebley & Associates

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Transcription:

1 MSO Lecture 3 Wouter Swierstra September 14, 2015

2 Haven t found a lab partner yet? Come talk to me in the break.

3 LAST LECTURE How can I manage the process of constructing complex software? How do I know what the customer wants?

4 FILL IN THE BLANKS... ERP stands for Enterprise Resource Planning think of software to manage accounting, HR, etc. (Source http://www.computerworld.com.au)

5

6 We estimate it would require an additional $1.1B for about a quarter of the original scope to continue and fielding would not be until 2020. The Air Force has concluded the ECSS program is no longer a viable option... Therefore, we are cancelling the program and moving forward with other options... An Air Force spokesman

The system dates back to 2005, when Oracle won an $88.5 million software contract, securing the deal over rival SAP and other vendors. It was supposed to replace more than 200 legacy systems. 7

8 1 BILLION DOLLARS WILL BUY YOU About 25 private jets.

9 1 BILLION DOLLARS WILL BUY YOU 40 private islands

1 BILLION DOLLARS WILL BUY YOU 10

11 This situation raises more questions than answers, Krigsman said. Why did it take the [Air Force] $1 billion and almost 10 years to realize this project is a disaster? What kind of planning process accepts a billion dollars of waste? Michael Krigsman, expert on IT project failures

Of course, this is only a problem for really large organisations, like the US Airforce, right? 12

13

14

15

16

17

18

19 THIS LECTURE How can we use our requirements and use cases to analyze and design software? What notation can we use to describe complex systems concisely?

20 NON-FUNCTIONAL REQUIREMENTS If use cases document the functional requirements, how should we document the other requirements? Typically, this is done in a Supplementary Specification. Chapter 7 of the Larman book has an example. Such a document typically includes: revision history; functional requirements (not covered in use cases, such as logging or error recovery); hardware and software constraints; legal issues; internationalization concerns; business rules;...

21 SUPPLEMENTARY SPECIFICATION FRAGMENT Functionality All bank machine transactions are logged to a centralized, persistent storage. Security Any usage of the bank machine requires identification via PIN and bank card. Usability The colour scheme should avoid those colours associated with colour blindness. Speed and ease of use are paramount in executing a transaction. Customers want to complete their transaction quickly and effectively. Under normal circumstances, it should be possible to complete common transactions in under two minutes.

22 REQUIREMENTS ARE NOT ENOUGH What good are requirements and use cases? They are not yet executable. They are written in natural language (Dutch, English, etc.) They are not precise enough to implement. There is further analysis and design necessary before you can deliver a fully functional system.

23 ANALYSIS The aim of analysis is to come up with an abstract model of the problem domain. You want to try and transfer requirements and use cases (written with the customer) to a technical specification (written for developers). A good model simplifies reality, but represents all relevant data.

MODEL: EXAMPLE 24

25 WHY MODEL SOFTWARE? Software is too complex to oversee all the details at once: we need abstractions! Windows 8 has about 50 million lines of code; Linux kernel has about 15 million lines of code; Code is written for a machine to execute not necessarily for a human to understand.

But how can we model software? 26

27 THE UNIFIED MODELING LANGUAGE The UML is a single language with 14(!) different dialects : use case diagrams; activity diagrams; class diagrams; sequence diagrams; and several others. It is the de facto standard way for designers, developers, business analysts, and any other technical stakeholders to communicate.

Before describing the process of analysis further, we need to describe some more the UML notation. 28

29 THE UML ACTIVITY DIAGRAMS Activity diagrams are useful to describe business existing processes. This can help to validate that you and your customer agree on how the current business works.

30 THE UML ACTIVITY DIAGRAMS They consist of: A single black dot the initial state; Rounded rectangles activities (File form, Ship order, etc.) Rectangles objects that are part of the workflow (Form, Invoice, Ticket, etc.) Diamonds (with labelled edges) choice points (If the decision is approved, If the item is in stock, etc.); Black bars represent the split and join of concurrent activities.

31

32

33 UML ACTIVITY DIAGRAMS Activity diagrams are particularly useful during the Business Modeling phase of the RUP where you establish how the current business processes work. The UML is not only about software development!

34 UML CLASS DIAGRAMS One of the most common UML diagrams is the class diagram, used to give a high-level overview of the software system. A class diagram consists of: boxes to represent classes (together with their attributes and methods); various arrows to describe the relation between classes. These diagrams are drawn at a varying level of detail, depending on the situation.

Square length : double display() 35

36 public class Square { public double length; } public void display() { \\ The implementation goes here return; }

37 Square - length : double + display() Use modifiers to indicate the visibility of methods and attributes: + indicates a method or attribute is public - indicates a method or attribute is private # indicates a method or attribute is protected There are further modifiers for packages, static methods, etc. Further details can be found in the UML documentation linked from the website.

38 DIFFERENT LEVELS OF DETAIL Square Square + display() Square - length : double + display() Choose the right level of detail, for the right situation: Early sketches: just use object name; Full design: complete overview of attributes and methods; Goal: communicate unambiguously with developers.

39 ABSTRACT CLASSES Abstract class Attribute Method Print the class name in an italic to define that class abstract.

40 RELATIONS BETWEEN OBJECTS A B The objects A and B are connected somehow. But can we be more specific?

41 SPECIFIC RELATIONS BETWEEN OBJECTS Inheritance A Dependency A B B Aggregation Composition A A B B

42 INHERITANCE Inheritance A B Pronounced: B is a subclass of A; B is derived from A; A is the superclass of B.

43 Inheritance A B public class B : A { // Class implementation goes here }

44 INHERITANCE EXAMPLE Vehicle Aircraft Road Vehicle Helicopter Fighter Jet Truck Motorbike

45 AGGREGATION Aggregation A A B B Read: A has a B; B is a part of A;

46 Aggregation A A B B public class A { public B myb; }

47 AGGREGATION OR ATTRIBUTE? Typically you should use: attributes to describe primitive types; aggregation to describe the relation with other classes.

48 AGGREGATION EXAMPLE Airport Aircraft Helicopter Jet Note that: The Aircraft class is kept abstract; Jets and Helicopters are subclasses of Aircraft. A picture is worth a thousand words

UML THIS abstract class Shape { private int width; private int height; public Color c; public int area() } public class Circle : Shape... public class Rectangle : Shape... There should be three colours, Red, Green, and Blue. 49

50 COMPOSITION Composition A B Composition is a special form of aggegration, where the contained object is a part of the containing object (and has no right to exist by itself or be referenced by other objects). The distinction is especially important in languages without garbage collection who is responsible for the clean-up?

51 DEPENDENCY Dependency A B Read: B depends on A; B uses A.

52 DEPENDENCY VS AGGREGATION The definition of aggregation is unambiguous, dependency is more subtle. Typically dependency is used when there is some relation between two objects, but not this is not an aggregation relation, for example: Objects of class A create objects of type B; Methods in class A take arguments of type B; Or the class A calls static methods of the class B. More generally, if a change to class A could affect class B, then A depends on B. A good design minimizes dependencies.

53 DIRECTED ASSOCIATIONS Person Company Person Company Person Company These pictures correspond to the following three situations: A person knows the company for which he works; A company knows its employees; Both person and company know about each other.

54 CARDINALITIES You may associate a number or range with any association, e.g. A 3 0..1 B Every A has 0 or 1 objects of type B; Every B has 3 objects of type A. Other examples: A car has four tires; You may borrow at most three books from the library.

55 LABELLED ASSOCIATIONS Sometimes you may want to label an association: Person Works for Company

56 UNDIRECTED ASSOCIATIONS Person Company A relation without arrow is said to be undirected This can mean two things: The exact relation is undecided; Both objects know about one another. I will work with the first definition. In the final design, avoid any such ambiguity!

57 THE UML VS CODE The UML is a great way to sketch out ideas. You can start very abstractly (just boxes and lines), and flesh out the design as you go along. A fully worked out UML class diagram can be translated to code (that doesn t do anything). Be careful it is easy to write UML diagrams that cannot be implemented.

58 PROBLEM? Apple Computer Laptop MacBook

A class may only have one superclass. 59

60 PROBLEM? Academic 1 FacultyMember Student 2

Adding constraints may result in unsatisfiable conditions. 61

62 PROBLEM? Library name : String Customer getbooks() Book ISBN : Int

63 MAKE SURE EVERY METHOD HAS THE INFORMATION IT NEEDS A class can only access: Its own private, public, or protected attributes/methods The public attributes/methods of other classes it has (aggregation) The protected and public attributes/methods of its superclasses.

64 WRITING PRECISE DESIGNS A design written using the UML is more than just a pretty picture it needs to be implemented using code. Compiler provide some sanity check that a program will execute. When you write a design, there is no compiler to check that your design makes sense. Convince yourself: check for common errors; replay use cases in your design; write explicit sequence diagrams and check that they are in accordance with the design.

65 SEQUENCE DIAGRAMS A class diagram captures the static structure of your system (which classes are related how?) but does not say anything about the dynamic behaviour (what happens when the code is run?) A sequence diagram is another UML diagram that captures the dynamic control flow of your program.

66 SEQUENCE BASICS A sequence diagram consists of a number of columns, representing objects. Horizontal arrows between objects represent method calls and returns. Boxes indicate an objects lifetime from creation to destruction. Time flows downwards.

67 SEQUENCE EXAMPLE Main :Data 1: setdata 2: getdata 3: returndata Time

68 SEQUENCE EXAMPLE Main :ShapeDB :Collection shape1:square :Display 1: getcollection 2: instantiate 3: instantiate 7: getcollection 4: addshape 8: sortshapes 9: displayshapes 10: display 11: displaysquare Time

UNIFIED MODELING LANGUAGE There are many other flavours of the UML for modeling both static structure and dynamic behaviour of code. Structural UML diagrams Class diagram Component diagram Composite structure diagram Deployment diagram Object diagram Package diagram Profile diagram Behavioural UML diagrams Activity diagram Interaction overview diagram Sequence diagram State diagram Timing diagram Use case diagram 69

70 ANALYSIS AND DESIGN Suppose you have talked to all the stakeholders... and written various use cases... and agreed upon a set of requirements... How do I make a great design?

71 BRIDGING THE GAP... A requirements document: is written in English; should be understood by the customer; aims to establish the system requirements. A design: is written using UML (class) diagrams; should be understood by developers; aims to communicate how to implement the system.

72 ANALYSIS Before fixing the design (or drawing UML class diagrams), it can be useful to define a domain model: specific to the problem domain; captures users s point of view; semi-formal notation light-weight UML class diagrams without methods; models the real world and not software components.

73 DOMAIN MODEL EXAMPLE Item * 1 Store adress name

74 WHY WRITE DOMAIN MODELS? Domain models help you to understand the entities a customer works, and your software system will handle. They help establish a common language with your customer. They provide a visual dictionary describing the relevant concepts in your domain. They are a first step towards defining the software system.

75 ANALYSIS HOW TO WRITE A DOMAIN MODEL? Talk to domain experts; Identify existing solutions/components; Identify design patterns (second half of this course); Textual analysis.

76 TEXTUAL ANALYSIS Once you start writing requirements and use cases, you quickly accumulate a lot of text. Try to use this text to identify parts of the domain: Nouns are good candidates for conceptual classes; Verbs are good candidates for associations.

77 TEXTUAL ANALYSIS TAKEN (FROM LARMAN 2002) 1. Customer arrives at checkout with goods to purchase. 2. Cashier starts a new sale. 3. Cashier records item description, price, and running total for each item. 4. System computes sales total, including tax. 5. Cashier informs Customer of the total and processes payment. 6. System logs completed sale, sends payment info to Accounting and Inventory departments. 7. System prints a receipt. 8. Happy Customer leaves with receipt and goods.

78 TEXTUAL ANALYSIS TAKEN (FROM LARMAN 2002) 1. Customer arrives at checkout with goods to purchase. 2. Cashier starts a new sale. 3. Cashier records item description, price, and running total for each item. 4. System computes sales total, including tax. 5. Cashier informs Customer of the total and processes payment. 6. System logs completed sale, sends payment info to Accounting and Inventory departments. 7. System prints a receipt. 8. Happy Customer leaves with receipt and goods.

79 SELECTING CONCEPTUAL CLASSES Customer, Checkout, System, Receipt: should these be an objects or not? What about Price, Total, Description? Are these objects or attributes? Are Items and Goods two words for the same concept?

80 TEXTUAL ANALYSIS 1. Customer arrives at checkout with goods to purchase. 2. Cashier starts a new sale. 3. Cashier records item description, price, and running total for each item. 4. System computes sales total, including tax. 5. Cashier informs Customer of the total and processes payment. 6. System logs completed sale, sends payment info to Accounting and Inventory departments. 7. System prints a receipt. 8. Happy Customer leaves with receipt and goods.

81 TEXTUAL ANALYSIS IDENTIFY VERBS 1. Customer arrives at checkout with goods to purchase. 2. Cashier starts a new sale. 3. Cashier records item description, price, and running total for each item. 4. System computes sales total, including tax. 5. Cashier informs Customer of the total and processes payment. 6. System logs completed sale, sends payment info to Accounting and Inventory departments. 7. System prints a receipt. 8. Happy Customer leaves with receipt and goods.

EXAMPLE (FROM LARMAN, CH 11) 82

A few common pitfalls in domain modeling 83

84 Cashier cashregister name But a cash register might be related to other objects...

85 Cashier name 1 1 Register number Tip: keep the types of attributes simple.

86 Cashier currentregisternumber name number Register

87 Cashier name 1 1 Register number Tip: favour associations over keys.

88 THE NOUN-VERB ANALYSIS The idea is very simple and easy to execute, but: Natural language is very imprecise; Many more nouns than relevant classes (more than one name for the same concept); The design is determined by your use cases but these two documents serve very different purposes. Don t be afraid to rephrase your use cases!

89 CASE STUDY: ELEVATORS The elevator has one button for each floor Light up when pressed Requests that the elevator stops at that floor The button s light is turned off once the elevator has stopped at the corresponding floor Each floor has two buttons to request the elevator to go up or down (except the first floor and top floor, which only have one): Light up when pressed Requests that the elevator stops at that floor The button s light is turned off is once the elevator has arrived at the floor. (Taken from Peter Müller s course on Software Engineering)

90 USE CASE: FETCHELEVATOR Main success scenario: 1. Passenger pushes button in the hall; 2. System lights up button; 3. System closes elevator doors; 4. System moves elevator to requested floor; 5. System turns off button s light; 6. System opens elevator doors.

91 USE CASE: RIDEELEVATOR Main success scenario: 1. Passenger pushes elevator button; 2. System lights up button; 3. System closes elevator doors; 4. System moves elevator to requested floor; 5. System turns off button s light; 6. System opens elevator doors.

92 REVIEW QUESTION Can you come up with a domain model?

93 USE CASE: RIDEELEVATOR Main success scenario: 1. Passenger pushes elevator button; 2. System illuminates button; 3. System closes elevator doors; 4. System moves elevator to requested floor; 5. System turns off button s light; 6. System opens elevator doors.

94 REVIEW QUESTION What sequence diagrams correspond to this use cases?

95 USE CASE: RIDEELEVATOR Main success scenario: 1. Passenger pushes elevator button; 2. System lights up button; 3. System closes elevator doors; 4. System moves elevator to requested floor; 5. System turns off button s light; 6. System opens elevator doors.

96 HOMEWORK EXERCISE What about the other use case, FetchElevator? What if the elevator needs to handle requests at any time (even if it is moving already)? How would this impact the domain model? The sequence diagrams?

97 VALIDATION After developing your domain model, you still need to validate it: Correctness: Does it accurately model reality? Completeness: Is every scenario (including the exceptional cases) described? Consistency: Does the model contradict itself? Unambiguous: Does the model describe one reality (and not many)? Realistic: Can the model be implemented?

98 HOW TO VALIDATE? You may use diagrams with different purposes (use cases, classes, sequence diagrams, etc.) to describe the same system. Do all these diagrams agree? Are all names consistent? Is every class described exactly once? No dangling associations? No two different classes with the same name?

99 MATERIAL COVERED Design Patterns explained. Chapter 2. Applying UML and patterns. Chapter 10 13 and Chapter 15 (Second Edition).