object oriented analysis and design: an overvie · 1 object oriented analysis and design: an...

45
1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of sources including Object Oriented Analysis and Design using UML by Ali Bahrami.

Upload: others

Post on 19-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

1

Object Oriented Analysis and Design: An Overview

Balaji Rajagopalan

Credits: Material for the slides is drawn from a variety of sources including Object Oriented Analysis and Design using UML by Ali Bahrami.

Page 2: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

2

What is Object Orientation (OO)?

• Traditional (structured) approaches viewed software along two orthogonal axes: Algorithms + Data Structures

• The OO centers on the object which combines the two orthogonal views

Page 3: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

3

Why OO?• Higher level of abstraction• Seamless transition among different phases

of software development• Encouragement of good programming

(Class carefully delineates interface -what the class can do and implementation of that interface - How the class does what it does)

• Promotes reusabilityNote that OO analysis and design does not make OO programming language a requirement for implementation

Page 4: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

4

The result of using the OO approach is…..

•Object-Oriented (OO) systems development is a way to develop software by building self-contained modules that can be more easily:

•Replaced

•Modified

•and Reused.

Page 5: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

5

Analysis Design Prototyping and Testing

ReturnBook? Yes

Go to counterand return the

book

BorrowBooks?

Done? Yes

Yes

No

PerformResearch?

InterLibrayLoan?

Yes

Inter LibraryLoan Section,

check outbook

No Search for thebook in the

library

Checkingout Books?

Go to counterand check out

the book

Yes Do Researchon the topic

No

Readnewspaper

/booksYes

Sitsomewhere

quiet and readnewspaper,books, etc.

No

Membercomes in

Business process modelingusing activity diagram

Checking AccountBank Client ATM Machine Account

Withdraw Checking Account

Withdraw Successful

Request Kind

Enter Kind

Request Amount

Enter Amount

Process Transaction

Transaction succeed

Dispense Cash

Request Take Cash

Take CashRequest Continuation

Terminate

Print Receipt

The advantage of developinga business process model isthat it familiarizes you withthe system and therefore theuser requirements

Use case diagramsUse cases capture the goal of theusers and the responsibility of thesystem to its users

Sequence diagramcollaboration diagram

The process of creating sequence or collaboration diagrams is asystematic way to think about how a use case can take place, and bydoing so, it forces you to think about objects involves in yourapplication

1. Identify the users/actors (Chapter 6): Who is (or will be) using the system?

2. Develop a simple businessprocess model

3. Develop the use case (Chapter 6): What are (or will be) the users aredoing with the system? Use cases provide comprehensivedocumentation of the system understudy

4. Interaction diagrams(Chapter 7) 4.1 Develop sequencediagrams 4.2 Developcollaboration diagrams. 4.3 Iterate and refine

5. Classification (Chapter 8) 5.1 Identify Classes 5.2 Identify Relationships 5.3 Identify Attributes 5.4 Identify Methods 5.5 Iterate and refine.

*

1

1

1

1

1..*

Class diagram

6. Apply design axioms to design classes,their attributes, methods, associations,structures, and protocols (Chapter 9)

6.1. Refine and complete the staticUML class diagram (object model)by adding details to the UML classdiagram (Chapter 10)

6.1.1 Refine attributes6.1.2 Design methods andprotocols by utilizing UMLactivity diagram forrepresentation of method’salgorithm6.1.3 Refine (if required)associations between classes6.1.4 Refine (if required) classhierarchy and design withinheritance

ViaNet Bank ATM Sytem

Account

Transaction

#transDate : Date#transTime : Time#transType : String#amount :float

#postBalance : float

Account

#number: String#balance : float

CheckingAccount

#savings : Account

SavingsAccount

#checking : Account

*

1

Account-Transaction

1

1

Savings-Checking

1..*

#transaction: Transaction#account : Account

+verifyPassword()

+deposit()

+withdraw()#retrieveAccount()

+withdraw()

#createTransaction()#updateAccount()

BankClient

#firstName : String#lastName :String

#pinNumber : String#account : Account

ATMMachine

#cardNumber : String

#address : String#state : String

#bankClient: BankClient

#transID : String

Refine UML Classdiagram

CheckingAccount::+withdraw (anAmount:Float):ReturnCode:String

insufficient funds

Withdraw usingAccount class

methodAccount.withdraw (anAmount)

sufficient funds

Doesn't have savingsaccount

withdraw usingSavingsAccount

method

SavingsAccount.withdrawSavingsAccount.balance -

(anAmount -CheckAccount.balance))

insufficient funds

acount has savingsaccount

returnCode="Insufficient

funds"

sufficient funds

returnCode ="OK"

Design methods byutilizing UML Activity

Diagram6.2 Iterate and refine (reapply Designaxioms).

7.0 Design the access ayer (Chapter 11)7.1. Create maccess layer classes by

mirroring the business classes7.2. Define relationships7.3. Simplify classes and structures

7.3.1 Eliminate redundant classes7.3.2 Eliminate method classes

7.4 Iterate and refine

8. Designing view layer classes (Chapter 12)8.1 Macro-level UI design Process- Identifying View layer Objects8.2 Micro-level UI design activities:

8.2.1 Designing the view layer objects by applying designaxioms and corollaries8.2.2 Prototyping the view layer interface.

8.3. Usability and user satisfaction testing (Chapter 14):8.4 Iterate and refine

Transaction

#transDate : Date#transTime : Time#transType : String

#amount :float#postBalance : float

BankClient

#firstName : String#lastName :String

#pinNumber : String#account : Account

Account

#number: String#balance : float

CheckingAccount

#savings : Account

ATMMachine

SavingsAccount

#checking : Account

BanK

*

1

Account-Transaction

1

1

Savings-Checking

1

1..*

Has

#cardNumber : String

#transaction: Transaction

#account : Account

#address : String#state : String

+verifyPassword()

+deposit()+withdraw()

-retrieveAccount()+withdraw()

#createTransaction()

-updateAccountt()

#bankClient: BankClient

#transID : String

BankDB

+retrieveClient()+updateClient()

+retrieveSavingsAccount()+updateSavingsAccount()

Access Class(es)

Business Classes

#bankDB: BankDB

#bankDB: BankDB

+retrieveCheckingAccount()+updateCheckingAccount()

-retrieveAccount()-updateAccountt()

#retrieveAccount()#updateAccountt()

UML Class diagramwith added accessand view classes

9. Iterate and refine the design/analysis: If needed repeat the precedingsteps

Create UserInterfacecontrols

Associate actionsto the User

Interface controlsand their events

Test/Debug

Enter title here

OKCancel

Create the forms and controls

Enter title here

OKCancel

Add Actions

Enter title here

OKCancel

Test the UIDone

Prototype user interface

10 9 8 7 6 5 4 3 2 1Very easy to use Very Hard to use

Is easy to operate:

How do you rate the ViaNet Bank ATM Kiosk Interface?

10 9 8 7 6 5 4 3 2 1Very appropriate Not appropriate

Buttons are right size and easily can be located:

10 9 8 7 6 5 4 3 2 1Very efficient Very inefficient

Is efficient to use:

10 9 8 7 6 5 4 3 2 1Very Not Fun at all

Is Fun to use:

10 9 8 7 6 5 4 3 2 1Very pleasing Not pleasing

Is visually pleasing:

Comments:

I have more to say, I would like to see you.

10 9 8 7 6 5 4 3 2 1Very easyrecovery Not at all

Provides easy recovery from errors:

Usability and usersatisfaction testing

Page 6: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

6

Object Basics•Define Objects and classes•Describe objects’ methods, attributes and how objects respond to messages,•Define Polymorphism, Inheritance, data abstraction, encapsulation, and protocol, •Describe objects relationships,•Describe object persistence,•Understand meta-classes.

Page 7: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

7

What is an object?• The term object was first formally utilized in the Simula language to

simulate some aspect of reality.• An object is an entity.

– It knows things (has attributes)– It does things (provides services or has methods)

Page 8: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

8

Attributes (Contd.)

I am a Car.I know my color, manufacturer, cost, owner and model.

Page 9: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

9

Attributes (Contd.)I am a Fish. I know my date of arrival andexpiration.

Page 10: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

10

It does things (methods)I know how to computemy payroll.

Page 11: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

11

Methods (Contd.)

I know how to stop.

Page 12: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

12

What is an object? (Contd.)• Attributes or properties describe object’s state (data) and

methods define its behavior.• Object is whatever an application wants to talk about.

– For example, Parts and assemblies might be objects of bill of material application.

– Stocks and bonds might be objects of financial investment applications.

Page 13: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

13

Objects

• In an object-oriented system, everything is an object: numbers, arrays, records, fields, files, forms, an invoice, etc.

• An Object is anything, real or abstract, about which we store data and those methods that manipulate the data.

• Conceptually, each object is responsible for itself.l A chart object is responsible for things like maintaining its data and labels,

and even for drawing itself.l A window object is responsible for things like opening, sizing, and

closing itself.

Page 14: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

14

Two Basic Questions• When developing an O-O application, two

basic questions always arise.– What objects does the application need?– What functionality should those objects have?

Page 15: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

15

Object’s Attributes and Methods• Attributes

– represented by data type. – They describe objects states.– In the Car example the car’s attributes are:

• color, manufacturer, cost, owner, model, etc.

• Methods – define objects behavior and specify the way in which an Object’s

data are manipulated.– In the Car example the car’s methods are:

• drive it, lock it, tow it, carry passenger in it.

Page 16: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

16

Objects are Grouped in Classes• The role of a class is to define the attributes

and methods (the state and behavior) of its instances.

• The class car, for example, defines the property color.

• Each individual car (object) will have a value for this property, such as "maroon," "yellow" or "white."

Page 17: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

17

Employee Class

Jane object Mark objectJohn object

Page 18: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

18

A Class is an Object Template, or an Object Factory.

B o e in g A i rp l a n e O b je c ts (B o e in g in s ta n c e s )

Page 19: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

19

Class Hierarchy• An object-oriented system organizes classes

into subclass-super hierarchy. • At the top of the hierarchy are the most

general classes and at the bottom are the most specific

Page 20: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

20

Class Hierarchy (Contd.)• A subclass inherits all of the

properties and methods (procedures) defined in its superclass.

Motor Vehicle

Truck CarBus

Page 21: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

21

Inheritance (programming by extension )

• Inheritance is a relationship between classes where one class is the parent class of another (derived) class.

• Inheritance allows classes to share and reuse behaviors and attributes.

• The real advantage of inheritance is that we can build upon what we already have and,

• Reuse what we already have.

Page 22: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

22

Inheritance (Contd.)

Ford

Vehicle

Car

Mustang Taurus Thunderbird

stop (m yM ustang)

I don’t know how to stop

I know how to stopstop m ethod is reusable

Page 23: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

23

Multiple Inheritance• OO systems permit a class to inherit from

more than one superclass. • This kind of inheritance is referred to as

multiple inheritance.

Page 24: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

24

Multiple Inheritance (Contd.)• For example utility vehicle inherits from Car and

Truck classes.

MotorVehicle

Truck Car Bus

UtilityVehicle

Page 25: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

25

Encapsulation and Information Hiding

• Information hiding is a principle of hiding internal data and procedures of an object.

Private Protocol

Public ProtocolMessages

Data

Permissible operations

Page 26: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

26

Encapsulation and Information Hiding (Contd.)

• By providing an interface to each object in such a way as to reveal as little as possible about its inner workings.

• Encapsulation protects the data from corruption.

Page 27: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

27

Protocol• Protocol is an interface to the object. • TV contains many complex components,

but you do not need to know about them to use it.

Page 28: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

28

Message• Objects perform operations in response to

messages. • For example, you may communicate with

your computer by sending it a message from hand-held controller.

Page 29: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

29

A Case Study - A Payroll Program

• Consider a payroll program that processes employee records at a small manufacturing firm. This company has three types of employees:

• 1. Managers: Receive a regular salary.• 2. Office Workers: Receive an hourly wage and

are eligible for overtime after 40 hours.• 3. Production Workers: Are paid according to a

piece rate.

Page 30: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

30

Structured ApproachFOR EVERY EMPLOYEE DOBEGINIF employee = manager THEN

CALL computeManagerSalaryIF employee = office worker THEN

CALL computeOfficeWorkerSalaryIF employee = production worker THEN

CALL computeProductionWorkerSalary

END

Page 31: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

31

What if we add two new types of employees?

• Temporary office workers ineligible for overtime,

• Junior production workers who receive an hourly wage plus a lower piece rate.

Page 32: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

32

FOR EVERY EMPLOYEE DOBEGIN

IF employee = manager THENCALL computeManagerSalary

IF employee = office worker THENCALL computeOfficeWorker_salary

IF employee = production worker THENCALL computeProductionWorker_salary

IF employee = temporary office worker THENCALL computeTemporaryOfficeWorkerSalary

IF employee = junior production worker THENCALL computeJuniorProductionWorkerSalary

END

Page 33: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

33

An Object-Oriented Approach

• What objects does the application need?– The goal of OO analysis is to identify objects

and classes that support the problem domain and system's requirements.

– Some general candidate classes are: – Persons– Places– Things

Page 34: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

34

What are some of the application’s classes?

• Employee• Manager• Office Workers • Production Workers

Page 35: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

35

Class Hierarchy

• Identify class hierarchy• Identify commonality among the classes• Draw the general-specific class hierarchy.

Page 36: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

36

Class Hierarchy (Contd.)Employee

OfficeWorker Manager ProductionWorker

nameaddresssalarySS#

dataEntryComputePayrollprintReport

dataEntryComputePayrollprintReport

dataEntryComputePayrollprintReport

Page 37: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

37

OO Approach

FOR EVERY EMPLOYEE DOBEGIN

employee computePayrollEND

Page 38: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

38

If new types of employees were added…E m p lo y e e

O ff ic eW o rk e r M a n a g e r P ro d u c tio nW o rk e r

n a m ea d d re s ss a la ryS S #

d a ta E n tryC o m p u te P a y ro llp r in tR e p o r t

d a ta E n tryC o m p u te P a y ro l lp r in tR e p o r t

d a ta E n tryC o m p u te P a y ro l lp r in tR e p o r t

T em p o ra r yO ff ic eW o rk e r

C o m p u te P a y ro l l

J u n io rP ro d u c tio nW o rk e r

C o m p u te P a y ro l l

Page 39: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

39

Polymorphism

• Polymorphism means that the same operation may behave differently on different classes.

• Example: computePayroll

Page 40: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

40

Associations

• The concept of association represents relationships between objects and classes.

• For example a pilot can fly planes.

Page 41: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

41

Associations (Contd.)

Pilot Planescan fly flown by

Page 42: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

42

Clients and Servers

• A special form of association is a client-server relationship.

• This relationship can be viewed as one-way interaction: one object (client) requests the service of another object (server).

Page 43: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

43

Clients and Servers (Contd.)

PrintServer ItemRequest for printing

Page 44: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

44

Objects and Persistence

• Objects have a lifetime.• An object can persist beyond application

session boundaries, during which the object is stored in a file or a database, in some file or database form.

Page 45: Object Oriented Analysis and Design: An Overvie · 1 Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of

45

Summary• Rather than treat data and procedures separately, object-oriented

programming packages them into "objects." • O-O system provides you with the set of objects that closely reflects

the underlying application• Advantages of object-oriented programming are:

– The ability to reuse code, – develop more maintainable systems in a shorter amount of time. – more resilient to change, and– more reliable, since they are built from completely tested and

debugged classes.