Department of Computer Science, York University Slides based on Object Oriented Software...

45
Slides based on Object Oriented Software Construction 22-06-23 12:22 1 Department of Computer Science, York University COSC3311 – Software Design Section P Vassilios Tzerpos

Transcript of Department of Computer Science, York University Slides based on Object Oriented Software...

Page 1: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 1Department of Computer Science, York University

COSC3311 – Software Design

Section P

Vassilios Tzerpos

Page 2: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 2Department of Computer Science, York University

Course Details

www.cs.yorku.ca/course/3311 Slides and other resources:

http://www.cs.yorku.ca/course/3311/sectionP/ Case studies:

http://www.cs.yorku.ca/course/3311/sectionM/ Eiffel Help:

www.cs.yorku.ca/eiffel

Office hours: WF 2:30 – 3:30 Read newsgroup

Lab hours next week: Monday, January 12 3-4 Wednesday, January 143-4 Friday, January 16 3-4

Page 3: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 3Department of Computer Science, York University

Grading

Assignment 1: 7% Assignment 2: 10% Assignment 3: 13% Test: 25% Exam: 45%

Page 4: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 4Department of Computer Science, York University

Textbook

Bertrand Meyer: Object-Oriented Software Construction, 2nd edition. Prentice Hall, 1997.

Suggested reading: Pete Thomas, Ray Weedon, Object-Oriented Programming

in Eiffel, second edition, Addison-Wesley, 1998. Kent Beck, Test-driven development : by example.

Addison-Wesley, Boston, 2003. J.M. Jezequel and C. Mingins. Design patterns and

contracts. Addison-Wesley, 2000. Erich Gamma et al.: Design Patterns. Addison-Wesley,

1995.

Page 5: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 5Department of Computer Science, York University

Advice – Course strategy

Don’t fall behind: First two weeks especially! Attend lectures: material is not all in textbook Do the readings on time

Page 6: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 6Department of Computer Science, York University

Week 1 – Readings

January 5 Software Quality & Engineering -- The context for design;

what is design; Eiffel programming; classes. Readings Required: Chapter 7

Static Structure Classes Class POINT …

Readings Background: Chapters 1, 2 External Quality Internal Quality – Modularity

Read about, install and use EiffelStudio

Page 7: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 7Department of Computer Science, York University

The goal: Software quality

REUSABILITY EXTENDIBILITY RELIABILITY (Correctness + Robustness) PORTABILITY EFFICIENCY …

Correctness: The ability of a software system to perform according to

specification, in cases defined by the specification. Robustness:

The ability of a software system to react in a reasonable manner to cases not covered by the specification.

Robustness

SPECIFICATION

Page 8: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 8Department of Computer Science, York University

Case Study 1– Bank example

Requirements & Use Cases Design – How?

Plan-driven: Identify the ClassesAgile: Test Driven Development

EiffelStudioClusters and ClassesTests and ETesterProject Configuration/Ace filesDebuggerDocumentation

Design ConstructsBONContractsObject equality: equalGenericityAgents and TuplesDesign Patterns (Singleton)

Page 9: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 9Department of Computer Science, York University

Requirements – Bank example

Requirements Open an account for a customer (savings or chequing) Deposit Withdraw Display details of an account Change LOC Produce monthly statements Print a list of customers …

Ambiguities What is the difference between savings and chequing? Many others …

Page 10: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 10Department of Computer Science, York University

Case Study 1 – Bank example

How should we go from Requirements to Code? Two basic approaches

Plan-driven (waterfall type models) Agile (incremental approaches)

Page 11: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 11Department of Computer Science, York University

Requirements to Code?

Code

How to bridge the gap between requirements and code?

???

Page 12: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 12Department of Computer Science, York University

The waterfall model of the lifecycle

FEASIBILITY STUDY

REQUIREMENTS ANALYSIS

SPECIFICATION

GLOBAL DESIGN

DETAILED DESIGN

IMPLEMENTATION

DISTRIBUTION

VALIDATION & VERIFICATION

PROJECT PROGRESS

Page 13: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 13Department of Computer Science, York University

Problems with the waterfall

Late appearance of actual code. Lack of support for requirements change — and

more generally for extendibility and reusability. Lack of support for the maintenance activity (70%

of software costs?). Division of labor hampering Total Quality

Management. Impedance mismatches. Highly synchronous model.

Page 14: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 14Department of Computer Science, York University

Impedance mismatches

As Management requested it. As the Project Leader defined it. As Systems designed it.

As Programming developed it. As Operations installed it. What the user wanted.

(Pre-1970 cartoon; origin unknown)

Page 15: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 15Department of Computer Science, York University

How to think about requirements?

Use Cases

Page 16: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 16Department of Computer Science, York University

Bank Requirements – Use Cases

System boundary

Use Case

Actors

Page 17: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 17Department of Computer Science, York University

Bank Use Cases

Challenge question:

What would the Use Case diagram look like if the bank supplies ATMs in addition to tellers?

Page 18: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 18Department of Computer Science, York University

Use Case – Open Account

Actors: Customer (initiator), Teller Overview: the customer applies for and is granted

a new bank account with some initial approved line of credit. The teller logs on to the system, selects open account , and supplies the new account details. The system prints a copy of the contents of the new account with the date, which the teller hands to the customer.

Page 19: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 19Department of Computer Science, York University

Design of Bank – Identify Classes

TELLER CUSTOMER SAVINGS_ACCOUNT CHEQUING_ACCOUNT MAIN_MENU BALANCE_INQUIRY INTEREST_RATE ………

Where do we start?

Page 20: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 20Department of Computer Science, York University

Test Driven Development

1. Write a little Test Test will not work initially (there is no code) Might not even compile

2. Make the Test work quickly Commit whatever sins are necessary in the process (e.g.

duplication in the code)

3. Refactor Eliminate the duplication created in merely getting the

test to work

Page 21: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 21Department of Computer Science, York University

EiffelStudio – create a new project

Page 22: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 22Department of Computer Science, York University

Call the new project bank

Page 23: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 23Department of Computer Science, York University

Compile and Run

print(“hello world!”)

Page 24: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 24Department of Computer Science, York University

Compile often!

Always start with a compiled system New project wizard Copy an existing system

A compiled system is needed for browsing Compile often!

Page 25: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 25Department of Computer Science, York University

ETester – Create a tests cluster

Click here

Page 26: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 26Department of Computer Science, York University

Create class ACCOUNT_TEST

Click here

Page 27: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 27Department of Computer Science, York University

Clusters and Classes

Page 28: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 28Department of Computer Science, York University

Ace file – Directory Structure

Directory (cluster)

Class file

d3d2d1

d4

f3.ef1.e

d0

Page 29: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 29Department of Computer Science, York University

Ace File – Ace.ace

system"bank“

rootroot_class: make

defaultprecompiled ("C:\Eiffel53\precomp\spec\windows\base")assertion (check)assertion (require) …

clusterroot_cluster: "."

all tests: ".\tests"

library base: "$ISE_EIFFEL\library\base"exclude

"table_eiffel3"; "desc"; end …

end

http://www.cs.yorku.ca/eiffel/precompiled

Page 30: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 30Department of Computer Science, York University

Project Configuration (Ace file)

Root Class All contracts

ACCOUNT_TEST turned on

Click here

Page 31: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 31Department of Computer Science, York University

Write Test

test_create_account: BOOLEAN islocal

c: CUSTOMERdo

comment("test_create_account")create c.make("Archie Fox")Result := equal(c.name, "Archie Fox")

end

Error code: VTCTError: type is based on unknown class.What to do: use an identifier that is the name of a class in the

universe.Class: ACCOUNT_TESTUnknown class name: CUSTOMER

Page 32: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 32Department of Computer Science, York University

The Test specifies a Design

Page 33: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 33Department of Computer Science, York University

customer.e

indexingdescription: "A bank customer“

class CUSTOMER createset_name

feature -- Element changemake (a_name: STRING) is

-- Create a customer. Set `name' to `a_name'.require

a_name_not_void: a_name /= Voiddo

name := a_nameensure

name_assigned: name = a_nameend

feature -- Accessname: STRING

-- of customerinvariant

name_not_void: name /= Voidend

Page 34: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 34Department of Computer Science, York University

ETester GUI – Green bar

Page 35: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 35Department of Computer Science, York University

Test: A customer with a savings account

test_create_customer_with_account: BOOLEAN islocal

a1,a2: SAVINGS_ACCOUNTc: CUSTOMERinitial_deposit: REAL

doinitial_deposit := 500create a1.make(initial_deposit)check a1.balance = initial_deposit endcreate c.make(a1, "Archie Fox")a2 := c.accountResult := equal(c.name, "Archie Fox") and

a2 = a1 and a2.balance = initial_deposit

end

Page 36: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 36Department of Computer Science, York University

Red bar

Page 37: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 37Department of Computer Science, York University

Use debugger to find problem

Page 38: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 38Department of Computer Science, York University

EiffelStudio – BON tool

Page 39: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 39Department of Computer Science, York University

Client-Supplier relationship

Page 40: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 40Department of Computer Science, York University

Open Account Use case (revisited)

Actors: Customer (initiator), Teller Overview: the customer applies for and is granted

a new bank account with some initial approved line of credit. The teller logs on to the system, selects open account , and supplies the new account details. The system prints a copy of the contents of the new account with the date, which the teller hands to the customer.

We have not yet dealt with the LOC, system menu and the receipt. We leave this as an exercise.

Page 41: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 41Department of Computer Science, York University

Withdraw Use Case

Actors: Customer (initiator) and Teller Overview: The customer provides the teller with an

account number and a withdrawal amount. The teller selects `withdraw-request’ from the system menu, and enters the data. The System debits the account by the requested withdrawal amount, and prints a receipt with the date and the amount, which the teller gives to the customer.

Question: What happens if there is not enough money in the account to withdraw?

Page 42: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 42Department of Computer Science, York University

test_withdraw

test_withdraw: BOOLEAN islocal

sa1, sa2: SAVINGS_ACCOUNTinitial_deposit: REAL

docomment("test_withdraw")initial_deposit := 500create sa1.make(initial_deposit)create sa2.make(200)sa1.withdraw(300)Result := equal(sa1, sa2)

end

Page 43: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 43Department of Computer Science, York University

Bank design (BON static diagram)

Page 44: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 44Department of Computer Science, York University

EiffelStudio feature tool – withdraw

Page 45: Department of Computer Science, York University Slides based on Object Oriented Software Construction 12/09/2015 11:05 PM 0 COSC3311 – Software Design.

Slides based on Object Oriented Software Construction 23-04-19 15:27 45Department of Computer Science, York University

Run tests