System Modelling. Lecture

Similar documents
System Modelling. Lecture

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

CS112 Lecture: Defining Instantiable Classes

Lecture 8: Iterators and More Mutation

CSE 70 Final Exam Fall 2009

CS445 Week 9: Lecture

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Chapter 6 Introduction to Defining Classes

PA3: Violet's Vending Venture (Version 3.0)

CPS122 Lecture: Detailed Design and Implementation

TOOLS AND TECHNIQUES FOR TEST-DRIVEN LEARNING IN CS1

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

Basic Object-Oriented Concepts. 5-Oct-17

COE318 Lecture Notes Week 8 (Oct 24, 2011)

Chapter 4 Defining Classes I

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Note that if both p1 and p2 are null, equals returns true.

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

TREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!

CPS122 Lecture: Detailed Design and Implementation

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

Midterms Save the Dates!

Instance Method Development Demo

Survey #2. Teen Talk Barbie TM Reloaded. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists

MSO Lecture 1. Wouter Swierstra (adapted by HP) September 11, 2017

Project Compiler. CS031 TA Help Session November 28, 2011

CMPT 126: Introduction to Computing Science and Programming Fall 2007, Harbour Centre

You must pass the final exam to pass the course.

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Comp Assignment 4: Extendible and Multi-Platform Object (De)Serialization

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

CIS 110 Introduction to Computer Programming Summer 2017 Final. Recitation # (e.g., 201):

Technical basis. Interfaces. Framework and tool overview

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Chapter 1 Getting Started

TREES Lecture 12 CS2110 Fall 2016

Introduction to Software Engineering in Java. Exceptions, I/O, and you++

Lecture 5: Implementing Lists, Version 1

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Object Orientation. A Crash Course Intro

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. February 10, 2017

ECE 122. Engineering Problem Solving with Java

A Java Execution Simulator

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static.

Problem and Solution Overview: An elegant task management solution, that saves busy people time.

The Stack, Free Store, and Global Namespace

Student Performance Q&A:

TESTING AND DEBUGGING

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. January 11, 2018

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Guessing Game with Objects

Tips from the experts: How to waste a lot of time on this assignment

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

PREPARING FOR PRELIM 2

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

CSCI 1301: Introduction to Computing and Programming Spring 2019 Lab 10 Classes and Methods

Computer Science E-119 Fall Problem Set 4. Due prior to lecture on Wednesday, November 28

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

CS Week 13. Jim Williams, PhD

CS1004: Intro to CS in Java, Spring 2005

Inheritance and Interfaces

1 Inheritance (8 minutes, 9 points)

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Example: Fibonacci Numbers

Designing a Database -- Understanding Relational Design

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

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

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

CSSE 220. Coupling and Cohesion Scoping. Please checkout VideoStore from your SVN

COP 3330 Final Exam Review

ASSIGNMENT 5 Objects, Files, and More Garage Management

Fall 2013 Program/Homework Assignment #2 (100 points) -(Corrected Version)

Software Engineering I (02161)

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

Introduction INF 5750


CSCU9T4: Managing Information

CAT.woa/wa/assignments/eclipse

EL2310 Scientific Programming

Code Reuse: Inheritance

COMP-202 Unit 9: Exceptions

CS 6371: Advanced Programming Languages

CSc 328, Spring 2004 Final Examination May 12, 2004

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

CS 1653: Applied Cryptography and Network Security Fall Term Project, Phase 2

CSC207 Week 3. Larry Zhang

Initial Coding Guidelines

MechEng SE3 Lecture 7 Domain Modelling

Object Oriented Relationships

ASSIGNMENT 5 Objects, Files, and a Music Player

Transcription:

System Modelling Lecture 02.10.2012

Lecture Objectives Storyboards as a base Objects to Classes GUI design with Story-Driven Modelling Intro to the project: 25pts

Story-Driven Modeling 1. Concrete behavior steps described by the client and captured in a scenario (working with client to make it concrete) 2. Modeling system "snapshots" with Object Diagrams for each scenario step and producing a Storyboard as a result 3. Modeling UML class diagram based on the Storyboard (still depends on experience) First step to abstraction (UML class diagram model only the static structure of program) Common mistake to use it for behavior design discussions 4. GUI Design and Initialization methods 3/59

Objects to Classes

Modeling UML class Diagram Going abstract Start assigning types to objects and keep an eye on the class diagram to avoid introducing of similar class twice Next, for each property of an object, we introduce an attribute declaration in the corresponding class Associations between classes and multiplicities based on the observed object diagrams 5/59

Modeling UML class Diagram? 6/59

Modeling UML class Diagram Simple Solution, but stresses the amount of logic needed to handle the special case of Exam room Restriction: nearly always bad idea, need to check initialization 7/59

Changes in plan? What if courses may move to the other rooms when student is studying? Hint: courses have some behavior and becoming mobile 8/59

Changes in plan? 9/59

Changes in plan? 10/59

Inheritance vs Association If there is some attribute/behavior that belongs to many classes

Inheritance vs Association ExamRoom Room Student 12/59 Student can be associated with objects of different class Capture this behavior in one place, like Space class

Modeling UML class Diagram A little more complicated and flexible solution if we expect changes in the plan 13/59 Example: If we introduce more kind of rooms (prerequisition to take the course)

Danger of Inheritance Hierarchy > 7 can explode the number of methods, confusing, poorly maintainable, overburdened local namespace Depth > 3 overridden methods that call each other and jumping around in the hierarchy are very difficult and error-prone to implement The derived class does not in practice, usually only specializes things, but often you have to overwrite methods in order to "generalize" behavior of the upper class, which contradicts the concept 14/59

Use of Inheritance Inheritance is usually used only in cases of fulfilling design pattern Don't use inheritance if you are unsure Maintanability, readibility become harder The bigger the project the more dangerous is inheritance Learn more in the Design Pattern course 15/59

Modeling UML class Diagram 16/59

Multiplicities and Associations Multiplicities and bounds Put bounds only when it is important for application Lower bounds: hardly ever Upper bound: seldom Try to introduce new object and keep logic for associations in one place 17/59

Classes to Code 18/59

Class Diagram to Code Trivial task that can be automatically performed using code generators class class Student Student {{ 19/59

Class Diagram to Code class class Student Student {{ private private String String name; name; void void setname setname (String (String name){ name){ this.name this.name = = name; name; String String getname getname ((){){ return return name name ;; 20/59

Class Diagram to Code class class Student Student { { private private String String name name ; ; void void setname setname (String (String name){ name){ if if (name (name == == null) null) { { throw throw new new IllegalArgumentException("Student.name IllegalArgumentException("Student.name must must not not be be null!"); null!"); this.name this.name = = name; name;...... 21/59

class class Student Student {{ private private University University university; university; void void setuniversity setuniversity (University (University university) university) {{ this.university this.university = = university; university; University University getuniversity() getuniversity() {{ return return university; university;...... 22/59

import import java.util.hashset; java.util.hashset; class class Course Course { { private private HashSet<Student> HashSet<Student> students students = = new new HashSet<Student>( HashSet<Student>( ); ); void void addstudent addstudent (Student (Student student){ student){ students.add students.add (student) (student) ; ; void void removestudent removestudent (Student (Student student) student) { { students.remove students.remove (student) (student) ; ; HashSet<Student> HashSet<Student> getstudents getstudents ( ( ){ ){ return return students; students; 23/59

UML to Code: Directed Association import java.util.hashset; class Course { private HashSet<Student> students = new HashSet<Student>( ); void addstudent (Student student){ students.add (student) ; void removestudent (Student student) { students.remove (student) ; HashSet<Student> getstudents ( ){ return students; 24/59 Although the accessor methods aim for protecting the container object from arbitrary outside modications, this goal isn't reached. Possible callers can still do the following: mycourse.getstudents().clear();

Courses Courses course course =....; ;...... course.getstudents course.getstudents (().clear ).clear( () ); ; course.getstudents course.getstudents (().add ).add(new EvilStudent EvilStudent (() )); ; // // now now all all student student references references are are gone gone // // possible possible parameter parameter check check of of addstudent addstudent (()) is is skipped! skipped! 25/59

import import java.util.collections; java.util.collections; import import java.util.hashset; java.util.hashset; import import java.util.set; java.util.set; class class Course{ Course{ private private Set<Student> Set<Student> students students = = new new HashSet<Student> HashSet<Student> ( ( ); ); boolean boolean addstudent addstudent (Student (Student student){ student){ return return students.add students.add (student); (student); boolean boolean removestudent removestudent (Student (Student student){ student){ return return students.remove students.remove (student) (student) ; ; Set<Student> Set<Student> getstudents getstudents ( ( ){ ){ // don't expose the concrete container class // don't expose the concrete container class return return Collections.unmodifiableSet Collections.unmodifiableSet (students) (students) ; ; int int sizeofstudents sizeofstudents ( ( ){ ){ return return students.size students.size ( ( ); ); 26/59

UML to Code: Bidirectional Associations Because both these references belong to the same association, we have to ensure that they're pointing to the opposite object (integrity). It would be an inconsistent implementation state, when a course refers lecture hall, but this lecture hall instance refers a completely different course instance! Let's add some code that manages the references to match. 27/59

class class LectureHall LectureHall { { private private Course Course course; course; void void setcourse setcourse (Course (Course course){ course){ if if (this.course (this.course!=!= course course ){ ){ Course Course oldvalue oldvalue = = this.course; this.course; this.course this.course = = course; course; if if (oldvalue (oldvalue!=!= null) null) { { oldvalue.setlecturehall(null); oldvalue.setlecturehall(null); if if (course (course!=!= null) null) { { course.setlecturehall(this); course.setlecturehall(this);...... 28/59

Same for the Course class class class Course Course { { private private LectureHall LectureHall lecturehall; lecturehall; void void setlecturehall setlecturehall (LectureHall (LectureHall lecturehall){ lecturehall){ if if (this.lecturehall (this.lecturehall!=!= lecturehall lecturehall ){ ){ LectureHall LectureHall oldvalue oldvalue = = this.lecturehall; this.lecturehall; this.lecturehall this.lecturehall = = lecturehall; lecturehall; if if (oldvalue (oldvalue!=!= null) null) { { oldvalue.setcourse(null); oldvalue.setcourse(null); if if (lecturehall (lecturehall!=!= null) null) { { lecturehall.setcourse(this); lecturehall.setcourse(this);...... 29/59

Methods and Initialization UML describes the static class structure Also class attributes and encapsulation Moving towards capturing behavior we introduce methods to initialize the dynamic objects structure from classes Starting from the static main method and continuing in the class constructors We again use the Storyboard as a base 30/59

Example A good start could be: class University { University ( ) { // more code or method calls goes here static void main ( String [ ] args ) { University uni = new University() ; // init rooms/lectures Uni.loadStudents(); // init students... 31/59

Example 32/59

Methods and Initialization Very straightforward Basically it is just a recreation of the structure shown on the object diagrams 33/59

Algorithm Design The most challenging task How application should solve the problem? Deriving general rules how things work Example: Newton derived the physical laws of gravitation from recognizing an apple falling from a tree Algorithm Design is not a modeling task 34/59

Algorithm Design However, the Storyboard can help you out: Get a common algorithm skeleton: developer needs to follow the behavior captured in the Storyboard starting from the initialization and divide each step to the sequence of simple subtasks simulating the computer's view Important to keep an eye on the initialized and reachable objects Use that skeleton to derive general rules: whether this operation (set of operations) works only for the given situation or whether it is a general operation that works in many/all situations

Example 1.The student Karli wants to achieve a degree at the Study- Right University. For a degree we need at the moment 214 credit points and Karli starts with 0 credit points and 214 motivation points. Karli is outside of the university and now enters the university into the math class. 2. Karli attends the math lecture and automatically earns 17 credit points for it and loses at the same time 17 motivation points. Karli has now 17 credit points and 197 motivation points. 3. Karli attends the modeling lecture and receives 29 credit points and loses 29 motivation points. Karli has now studied math and modeling and therefor has now 46 credit points and 168 motivation points.... 36/59

Example 1.Enter the university (get to the first room, initialization) 2.Execute room activity 3.Choose the next room 4.Enter the room 5.Execute room activity 6... Main logic here 37/59

Amending Storyboard Let storyboard be a center of the modeling process Add comments to the scenario steps to highlight general behavior Add comments to point to the specific cases Add comments to clarify behavior with the customer 38/59

Story-Driven Modeling Method Overview Customer Interaction Scenarios Object Diagrams Customer Interaction Storyboards UML Class Diagram Classes Attributes Initialization Methods Algorithm Design * C O D E * C O D E * C O D E * C O D E *

Interaction with Customer and Tests Interaction with customer is continuous and aimed to concretize the application behavior Continuous improvement of the Storyboard Storyboards can very easily be adapted to tests Story-Driven Modeling is very close to the Test-Driven Modeling *http://c2.com/cgi/wiki?testdrivendevelopment

GUI Design with SDM

Example Application Imagine a party/social where participants would like to split the bill very exactly. this behavior is strangely referred to as going dutch in English Imagine that only several people have time to go and really buy something. Usually this ends up with one person who takes on the task of creating a register of all stuff brought, how much people spent on it, and computing and redistributing the money to even it out. Therefore, we will call our application the Group register. 42/59

Wireframes or Mockups 43/59

Wireframes or Mockups Often created manually on paper For customer it is difficult to differentiate GUI elements of editor from the designed application Often GUI is refined together with customer who is often missing design app. skills Designers vs Developers Usability vs code complexity 44/59

1. Karli, Bobby, and Olga agree to have a pot luck barbeque, but want to share the cost evenly. On the day of the barbeque, Karli brings his notebook running the Group Register application. He assumes that Bobby and Olga will bring enough for them all, so he does not bring any food items. After starting the application it shows the initial screen of the application with no entries. This step mentions that we have an application with an initial screen

2. Karli adds himself, Bobby, and Olga to the list of participants This step mentions a list of participants. Therefore we need a list showing the names of the participants. But how we will actually get the participants into the list? 46/59

A B C

a) Just editing the table *This requires complex handling of a single dummy line in the end of the table and might pose some difficulties in programming b) Having some fields and an add button underneath to enter one person at a time c) An add button on top which creates an empty line, which is editable * Combined idea from a) and b) but still needs more programming than b) Lets say that customer agreed decision b) 48/59

3. Bobby shows up and brings some beer for 12 EUR. Karli enters that Bobby brought beer for 12 EUR into the system. Olga brings bread for 4.50 EUR and salad for 3.00 EUR. Karli enters the items for Bobby and Karli to the system. From this step, we can derive that we need something to store bought items, the person who bought it, and the price of each. This also suggests to use some kind of table with the columns person name, item description, and price. Also here, we could discuss different options to fill in the values like in the last step, but also here we will settle on the option of adding some entry fields and an add button. This could be done in a different window, but we will put it in the same to make all information visible at all 49/59

50/59

4. The food items sum up to 19.50 EUR. Therefore, the share of each participants equals to 6.50 EUR. As Karli has not spent any money for food items, he has to pay the full share of 6.50 EUR. As Bobby has already spent 12 EUR, he has to receive back 5.50 EUR. Olga has spent 7.50, so she has to receive 1 EUR back. So far we have not taken into account that we want to also see the amounts of the balance each participant has to pay to the register. We could now either add a button to compute the balance and show a different window with the results or we could also show the balance all the time in the participant's list. Let us assume that our potential customer prefers the version seeing the balance all the time. We therefore add a column Amounts.

52/59

Refining the Storyboard Further playing with these wireframes might lead to some further requirements and ideas Will it be possible to remove items from the list? How exactly? Will it be possible to edit the names of the participants? Client might discover that he needs to be able to adjust the price of the food items.... 53/59

Choosing the Right Container Class java.util.set java.util.hashset java.util.treeset 54/59

Choosing the Right Container Class java.util.set java.util.hashset java.util.treeset java.util.list java.util.arraylist java.util.linkedlist java.util.vector 55/59

Choosing the Right Container Class java.util.set java.util.hashset java.util.treeset java.util.list java.util.arraylist java.util.linkedlist java.util.vector java.util.map 56/59

Course Project Develop a desktop multiplayer version of the game Backgammon using Story-Driven Modelling method You can see an example implementation Wikipedia has a compact description Taken from: http://www.phillaakpoker.com/wp-content/uploads/2010/05/backgammon.jpg 57/59

Project Documentation The project report you will have to hand in has to consist of: A guide through your project (and repository) Code + compiled executable Your project plan (scheduler, requirements, aims..) Project log (progress) Class Diagram (+explanations of your decisions) Storyboard (as detailed as reasonable) Also simulate customer discussion, try to find/think out 3-5 additional features 58/59

Project Presentation The deadline for the assignment is 12.10 (23:59) Submit as zip file on the website Course project presentations (10-15 min) on 16.10,17.10,18.10 (lab sessions) Talk about solved/not solved problems How you organized the work Some notes about the SDM method Application demo 59/59