105
1 Object-oriented design 1. Introduction 2. Software life-cycle model 3. OO analysis -structure analysis 4. UML : Notation use case, class diagram 5. OO analysis-behavior analysis &implement-component deployment 6. Object-oriented design 7. Testing Final ศุกร์ 13 .. 59 15.30-18.30

Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

Embed Size (px)

Citation preview

Page 1: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

1

Object-oriented design1. Introduction2. Software life-cycle model3. OO analysis -structure analysis4. UML : Notation use case, class diagram5. OO analysis-behavior analysis &implement-component deployment

6. Object-oriented design7. Testing

Final ศกร 13 พ.ค. 59 15.30-18.30

Page 2: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

2

บทท 6 Designsystem design & detailed design

6.1 สงทเราตองการจาก notation ทเรา document6.2 objective ของ object-oriented design 6.3 Object-oriented architecture

Problem domain component (PDC)Human interaction component (HIC) input/output Task management component (TMC) Data management component (DMC)

6.4 Criteria ทใชในการออกแบบ6.5 ภาษาทใชในการ implement

Page 3: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

3

Analysis

Analysis identifies ‘what’ the system must do

เราวเคราะห system วาจะทาอะไรไดบาง เปนอยางไร

The analyst seeks to understand the organization, its

requirements and its objectives

Design

Design specifies ‘how’ will do it

เราจะ implement system ไดอยางไร เครองทใช

ภาษาทใช OS เปนอยางไร เพราะเหลานมผลตอการ design

เราตองคานงวาเราจะ implement ไดอยางไร

Page 4: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

4

As an example : class Campaign

– analysis identifies the fact that the Campaign class has a title attribute

– design determines how this will be entered into the system, displayed on screen and stored in a database, together with all the other attributes of Campaign and other classes

Page 5: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

5

notation ทใช document ในการ design

เราใช notation เดยวกบการวเคราะห เราตองการอะไรจาก diagram ??

จดประสงค ทเราใช diagram คอ เพอ document ความคดของเรา

ระบบเราเปนอยางไร มใคร มาทาอะไร อยากไดอะไร ..

เราจะวเคราะห+ออกแบบ diagram

เราตองดงความคดของเราออกมา

diagram อานงาย เขาใจงาย (standard UML)

เพอdocument สงทเราตองการใหได

จาก OOA OOD ไมมรอยตอ(seamlessness) same model และ

During design, additional detail is added to the analysis classes, and extra

classes are added to provide the supporting functionality for the user

interface and data management

Page 6: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

6

6.1 สงทเราตองการจาก notation ทเรา document คอ

1.visibility เราสามารถแบง attribute แบง service เปน private

public protected ซง notation ควรจะมใหเรา เราจะได document ได

private ใชไดเฉพาะ classนน

public objectอนสามารถaccess ได

protect ถายทอดให subclass

ใน C++ ม friend function คอ operation ไหนเปน friend กบใคร

ก access ไดหมด ทง private protect เหมอนเปน method นนเลย

?? หากเรากาหนด เชนน จะสวนทางกบหลกการของ OO

การทาเพอimplementใหระบบทางานได

??

ตอบ...

1. Visibility2. Persistence3. Exception

Page 7: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

7

2. persistence หมายถง object ไหนบางทเราตองการใหมนคงอย แม program จะยกเลกไปแลว

เรายงตองการเกบ information คอเกบในsecondary storage และยง

ระบวา จะลบไดอยางไร ในเมอมน persistence

3. exception คอการ document พวก error ตางๆ ทไมใช error จาก user เปน error ทเกดจาก technology จาก ฮารดแวรตางๆ

จาก bug ใน object อนๆ เชน สง message อะไรไมรมาให ซงเราไมม

serviceน เราจะทาอยางไร

user error

Software error

hardware error

Exception handling

Page 8: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

8

4. containment การ group object group service เปน module

package ไดอยางไร

5. concurrency object ไหนเปน active passive object

object ไหน process ไดมากกวา 1 message ในระยะเวลาหนง

คอ เกยวกบconcurrencyและ synchronization

6. collection หมายถงพวก set list ตางๆ เราจะม generic type หรอไม เพอสราง type อนๆ ขนมา

7. constraint เปนการกาหนด constraint precondition

postcondition เพอใหแนใจวา system run ไดถกตอง

1. Visibility2. Persistence3. Exception4. Containment5. Concurrency6. Collection7. constraint

Page 9: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

9

Prototype

การทา analysis และการ design ตองทา prototype ดวย เพราะการ

ทา prototyping นน จะชวยไดดงน • identify user requirement หากเราขาด/พลาดอะไรไป จะได

improve ได• user สามารถใช user interface ทเราออกแบบ และเขาพอใจ

หรอไม• เปนการ test designจากทเราคดวาจะ implement อยางไร พอ

design แลวทา prototype จะรวาทเรา design นนถกหรอไม performance เปนอยางไร

• ทาให user เหนวา เรามสามารถในการทา และเขาใจ concept ตางๆ ท user ตองการ

Page 10: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

10

6.2 objective ของ object-oriented design

1. improve productivity

- ใชเวลาในการ test การทา productivity นอยลง

เพราะวา เรา design มาแลวเปนอยางด

- ม class library ซงซอมาหรอจาก project เกาๆ ท

ใช OO ซง classเหลานนเกบไวใน class library เมอ

สราง project ใหม กสามารถนา class เดมใน

library มาใชได จงใชเวลาในการทาไดเรวขน

Page 11: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

11

2.increase quality

qualityนไมใชแคคณภาพหรอความถกตองเทานน

รวมถง งายตอการใช , modify , portable

เรา quality ใหดขนดวย OO โดย

(ปกตเรา test product เมอ develop เสรจแลว) แตเวลา

ทา OO เราทา prototype ไป design ไป กทราบวา

ถกตอง อยใน trend หรอไม

error ตางๆ กเจอใน phase แรกๆ

Page 12: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

12

3.elevate maintainability

ทาอยางไรถงจะ design system ทสามารถเปลยนแปลง

ไดตลอดเวลา

วธการคอ แบง system เปนสวน ๆ

- สวนท stable คอ structure ของ class , จานวน class ,

ความสมพนธระหวาง class ซงอาจมอยางอนมา add เพม กไม

กระทบของเดม

Page 13: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

13

-สวนทมการเปลยนแปลง

• สวนทตดตอกบผใช (Human Interaction Component)

• ความยงยากของ algorithm ของ service หรอ operation

ซงกระทบกบ service ตวนนตวเดยว (interface , ชอ

message, จานวน parameter ยงเทาเดม) actionของ

algorithm เปลยนแปลงไปอยางไร สวนอนไมกระทบ

• attributeซงกระทบ classนน class เดยว

Page 14: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

14

Motive and benefit ของ OOD (มประโยชนและประสงคอยางไร)1. ทาใหเราสามารถเขาใจ problem domain ไดดย งข น2. ทาใหการตดตอระหวาง นกวเคราะห นกออกแบบ programmer user เขาใจไดดย งข น เพราะวาใช concept เดยวกน3. ม consistence ระหวาง analysis design & implement เพราะวา ใช concept เดยวกน : encapsulation class object inheritance composition generalization specialization polymorphism เปนตน4. สามารถ represent ความเหมอน(commonality) ของ attribute ของ service ออกมาได โดยใช generalization specialization structure5.สามารถสราง system ทพรอมกบการเปลยนแปลง เพราะวาเราแบงเปนcomponent หากเปลยนแปลงกเปลยนเฉพาะใน component ไหน ใน class ไหนเทาน น6. reusabilityใชผลลพธจากระบบเกา คอ ใช class library7.ม consistency ระหวาง representation ของ analysis design programming คอใช diagram เดยวกนไป analysis ไป design ได ในการวเคราะห เรา define class define object ใหตรงกบ problem domain การ design เรา identify class identify object ซงอาจมการgroup หรอทาอะไรเพอทจะ implement

Page 15: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

18

6.3 Object-oriented design architectureใน object-oriented design architecture แบงได 4 สวน1. Problem domain component (PDC) - entity ทาแลวตอนวเคราะห นามาใชไดเลย อาจตองเปลยนแปลงบางอยาง2. Human interaction component (HIC) - boundary

คอ component เกยวกบการรบinput การ display output กบ user3. Task management component (TMC)

component ททาการควบคม task ตางๆ ทาการ synchronization คอ ตองการ concurrency ถงทา task management

4. Data management component (DMC)เกยวกบการเกบ data ลง secondary storage (save object ลง file ลงsecondary storage ) อาจม class ม object เพม เพอเกบในsecondary storage

Page 16: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

19

6.3.1 Problem domain component (PDC)

การ design PDC นน เราสามารถนาผลของการ

วเคราะหมาไดเลย แลว improve

(หาก requirement เปลยน / policyเปลยน-กปรบเปลยน)

ซงการ improve นนอาจตอง add บางอยางเขาไป

PDC HICDMC TMC

OOD architecture

Page 17: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

20

Object-oriented detailed design adds detail to the analysis model

– types of attributes

– operation signatures

– assigning responsibilities as operations

– additional classes to handle user interface

– additional classes to handle data management

– design of reusable components

– assigning classes to packages

Analysisdesign

Add detail to analysis

From analysis to design

Page 18: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

21

1. class specification ทมรายละเอยดมากขน

2. interfaces

3. association 1 to 1, 1 to M , M to M

ตวอยาง detailed design

Page 19: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

22

1.Class Specification:

Attribute Operations Visibility

BankAccount class with visibility specified –private +public # protected ~ package

BankAccount- nextAccountNumber: Integer- accountNumber: Integer- accountName: String {not null}- balance: Money = 0- availableBalance: Money- overdraftLimit: Money

+ open(accountName: String):Boolean+ close(): Boolean+ credit(amount: Money): Boolean+ debit(amount: Money): Boolean+ viewBalance(): Money# getBalance(): Money- setBalance(newBalance: Money)# getAccountName(): String# setAccountName(newName: String)

BankAccount classwith the attribute

data types included

BankAccount classwith operation

signatures included.

ตวอยาง

Page 20: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

23

interfaces for the Advert class

- staffNo - staffName - staffStartDate - qualif ication

CreativeStaff

+ calculateBonus() + linkToNote()

- title - type - targetDate - estimatedCost - completionDate

Advert

+ getCost() + setCompleted() + view()

Realize relationships

«interface» Manageable

+ getCost() + setCompleted() + view()

«interface» Viewable

+ view()

Manageable Viewable

- companyName - companyAddress - companyTelephone - companyFax - companyEmail - contactName - contactTelephone - contactEmail

Client

+ assignStaffContact() + changeStaffContact()

«use» «use»

«realize» «realize»

2.interfaceตวอยาง

Page 21: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

24

3.Association

1 to 1

1 to M

M to M

Page 22: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

25

Designing Associations

One-way one-to-one association

Owner

- name : String- address : Address- dateOfLicence : Date- numberOfConviction : Integer- ownedCar : Car

owns

1

Car

- registrationNumber : Registration- make : String- model : String- colour : String

1carObjectId is placed in the Owner class

Arrowhead shows the direction in which

messages can be sent.

ตวอยาง

Page 23: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

26

One-to-many association using a collection class.

has1

*

1

- title: String- campaignStartDate: Date- campaignFinishDate: Date- estimatedCost: Money- completionDate: Date- datePaid: Date- actualCost: Money- ownedAdvertCollection: AdvertCollection

Campaign

+ assignManager()+ assignStaff()+ checkBudget()+ checkStaff()+ completed()+ getDuration()+ getTeamMembers()+ linkToNote()+ listAdverts()+ recordPayment() - title: String

- type: String- targetDate: Date- estimatedCost: Money- completionDate: Date

Advert

+ getCost()+ setCompleted()+ view()

owns

- ownedAdvert : Advert [*]

AdvertCollection

+ findFirst()+ getNext()+ addAdvert()+ removeAdvert()

1

Page 24: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

27

Two-way Many-to-many Associations

This is the design for the works On Campaign association

CreativeStaff

- staffCampaigns: CampaignCollection

+ listCampaigns()

work on

* 1

CampaignCollection

- staffCampaign: Campaign [*]

+ findFirst()

+ getNext()

+ addCampaign()

+ removeCampaign()

+ findCampaign()

StaffCollection

- campaignStaff: Staff [*]

+ findFirst()

+ getNext()

+ addStaff()

+ removeStaff()

+ findStaff()

Campaign

+ listStaff()

work on

has

has

1

1

1

*

1

*

class diagramp207

- staffCollection:StaffCollection

Page 25: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

28

ใน PDC เมอเขาส Design : การปรบเปลยนanalysis เกยวของกบ (1-6)

1. reusability 2. group class ทม protocol เหมอนกน เปน class

เดยวกน: 3. ทาgen/spec :protocol เหมอนกน กไปอยท superclass 4. inheritance ปรบ:single/multiple: ภาษา5. improve performance6. support DMC

Detail 1-6 Next page

Page 26: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

29

1. reusability เวลา design กดผลลพธจากการวเคราะหวาใน library มclassตรง/คลาย class ไหนบาง ทเราใชได

คอ หาก

- เหมอน กใชแทนไดเลย

- หากมมากกวา คอ หลงจากทา gen-spec แลว ในlibraryม class ไหน ทไมตองการก

ตดทง(ไมใชไมใส)

- หากมนอยกวา กนามาเปน generalization แลว develop เพมเฉพาะสวนทเกน

From analysis to design1.reusability 2.group class ทม protocol เหมอนกน เปน class เดยวกน: 3.ทาgen/spec :protocol เหมอนกน กไปอยท superclass 4.inheritance ปรบ:single/multiple: ภาษา5.improve performance6.support DMC

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

Page 27: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

30

2.การ group class เขาดวยกน (จาก 2 class , 3 class

เปน class เดยวกน) เพราะเราม class บาง classท

ม protocol เหมอนกน ( พวกการเกบลง file )

(protocolทจะตดตอกบ DMCเหมอนกน) เราจง

group เขาเปน class เดยวกน

3.แทนทจะ group เราอาจทาgeneralization แลวclass

ตางๆ ทม protocol เหมอนกน กไปอยท superclass

แทน

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

From analysis to design1.reusability 2.group class ทม protocol เหมอนกน เปน class เดยวกน: 3.ทาgen/spec :protocol เหมอนกน กไปอยท superclass 4.inheritance ปรบ:single/multiple: ภาษา5.improve performance6.support DMC

Page 28: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

31

4.inheritance เมอเราวเคราะหแลวได multiple inheritance แตภาษาทใชมแต single inheritance เรากตอง designใหม ซงมหลายวธ

-จาก multiple inheritance ให split เปนหลายๆ single

inheritance

เชน Person

Owner

Role

clerk

ทางแกไข

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

Page 29: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

32

4.1 split เปนหลายๆ single inheritance แลวทา connection กน

Person

ClerkOwner

Role

Clerk RoleOwner Role

Person

ClerkOwner

Role

Clerk RoleOwner Role

หรอ

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

Page 30: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

33

หรอ 4.2 ทา single inheritance เลย ยอมใหมการ duplicate

เราตองเพม attribute ทเปนของ role เขาไป owner clerk

เราตองเพม service ทเปนของ role เขาไป owner clerk

ดงนน class Role กไมม

ยอมใหหายไปบางสวนเพอ

implementใหได

คอ ยอมใหม duplicate

Person

ClerkOwner

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

Page 31: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

34

5.improve performance คอ run ไดเรวเพยงพอในราคาและschedule ทให

เวลา design จะ improve performance ไดแคไหน เราตอง

คานงถง

-improve ความเรว เราไมคานงมากนก เราจะทาตอนสดทาย เมอ system run แลว

-ลด overhead

เราไมคานงมากนก จะดเมอ system run แลว

- แทน solution เกาดวย solution ใหมทฉลาดกวา

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

From analysis to design1.reusability 2.group class ทม protocol เหมอนกน เปน class เดยวกน: 3.ทาgen/spec :protocol เหมอนกน กไปอยท superclass 4.inheritance ปรบ:single/multiple: ภาษา5.improve performance6.support DMC

Page 32: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

35

6.ทาเพอ support Data Management Component (DMC) ซง

อาจตองเพม service หรอ attribute

ใน object เพอให save object หรอบอกให DMC ให save

object ลง file

คอ การ save ม 2 วธ

6.1- ให object save ตวเอง ใหรวาจะ saveไดอยางไร

6.2- ให DMC ทาให ซงตองสง message ไปให DMC

และจะทาอยางไร DMC ถงจะรวา save ใคร save

อยางไร attribute ทเราตองเพมเขาไปคอ class name เพอ

บอกวา object นอย class อะไร

PDC HICDMC TMC

detail

การเปลยนแปลงผลลพธของ analysis เพอใหได PDC เราตอง concern เกยวกบ

Page 33: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

36

service ในการ save ตวเอง ทาได 2 อยาง ขนกบภาษาทใช

- single inheritance ทก ๆ object ตองม serviceน

- multiple inheritance สราง generalization class หนงทม service น

และ classตางๆ ทตองการเกบลง file จะเปน subclass ของ

generalization น

support DMCคอม OODBMS ซง DBMS จะจดการกบobject

ทงหลาย (การเกบ การดง object) เราทา connection เทานน

กได DMC มา

6.1 save ตวเอง

6.2 . ให DMC ทา

OODBMS (Object-oriented DB Management System) is a database

with data stored in objects and collections NOT rows and tables

Page 34: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

37

นอกจากนเมอเขาส Design :เปลยน analysis เกยวของกบ1. reusability 2. group class ทม protocol เหมอนกน เปน class เดยวกน: 3. ทาgen/spec : protocol เหมอนกน อยท superclass 4. inheritance ปรบ:single/multiple: ภาษา5. improve performance6. support DMC

PDC HICDMC TMC

PDC

detailed design ex. class spec. / interface / association

สรป

6.3 Object-oriented design architecture

Page 35: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

38

6.3.2 Human Interface Component (HIC)

คอ component ทรบ input จาก user และแสดง output

ให userเหตผลทตองแยก component นจาก PDC

เพราะ user interface เปลยนแปลงงาย

technology เปลยนแปลงไปเรอยๆ

HIC เปลยนแปลงงาย

หากเรารวม interface ไวใน Problem domain

เปลยนแปลง user interface จะกระทบหมด จงแยกออกมา

หากตองการเปลยน user interface เปลยนเฉพาะcomponent น

PDC HICDMC TMC

6.3 Object-oriented design architecture

Page 36: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

39

นนคอ ใน HIC กจะประกอบไปดวย object ตางๆ ทเปนเงาของ objectใน problem

domain (คอรบ input เขามาใสในobject แลวถงจะสง message ไปให problem

domain เอาคา input ใสเขาไป)

HIC จะม object ทรบ input (เกยวกบการรบ)

object ท display output (เกยวกบการ display)

ซงเราตองดวาม tools อะไร

แลวสรางจาก tools ทมให เพอสราง user interface ไดงายๆ

การ design human interface ทด ควรทาควบคไปกบการทา prototyping

เพอเราจะไดรวาuser ชอบหรอไม ดหรอไมดจะไดแกไขแตตนๆ ซงการ

design สวนน เราทาควบคไปกบตอน analysis

HICok เราจะทา HIC เราจะตองทาอยางไร

Page 37: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

40

Check Campaign Budget

Use Case Prototype

In this prototype, Clients and Campaigns are selected in drop-down lists

There are other ways…

Design Prototype HIC

Page 38: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

41

Collaboration for

Check campaign budget

Check Campaign BudgetUI

Check Campaign

Budget

Campaign Advert

List Campaigns

List Clients Client

1.

2.

3.

1.2.3.

entity

Design Prototype HIC

Page 39: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

42

Class Diagram: Stereotypes

Analysis class stereotypes differentiate the roles objects can play:

Boundary objects model interaction between the system and actors (and other systems)

Entity objects represent information and behaviour in the application domain

Control objects co-ordinate and control other objects

Control::AddAdvert

showClientCampaigns( )showCampaignAdverts( )createNewAdvert( )

User Interface::AddAdvertUI

startInterface( )assignStaff( )selectClient( )selectCampaign( )

<<boundary>>Campaign

titlecampaignStartDatecampaignFinishDate

getCampaignAdverts( )addNewAdvert( )

<<entity>>

Design Prototype HIC

เรยนแลว

Page 40: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

43

Class Diagram for CheckCampaignBudgetUI

3

1

2

1

1

1

2

1

Dialog

CheckCampaignBudgetUI

Label Button TextField Choice

Design Prototype HIC

Page 41: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

44

Package Dependencies

Classes can be shown with package names

3

1

2

1

1

1

2

1

java::awt::Dialog

CheckCampaignBudgetUI

java::awt::Label

java::awt::Button

java::awt::TextField

java::awt::Choice

ภาษา Java : package awt เกยวของกบ graphic

HIC

Page 42: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

45

strategy ในการ design1. classify the human2. describe human and their task3. การ design command hierarchy4. design detail interaction between user and system5. design HIC classes necessary to manage the interaction 6. continue prototyping

HIC

Page 43: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

46

strategy ในการ design1. classify the human เราจะแบง user เปนกประเภท มหลายวธ

– ตามความชานาญในการใช computer– ตามตาแหนงหนาทการงาน– ตาม group

เราแบงเพอดวา เขาตองการอะไรจากระบบเรา ทาอยางไรเขาถงจะทางานสาเรจ ตองม tools อะไรหรอไม

2.describe human and their task อธบายหนาทการงานของเขาจรงๆ ตามความตองการของเขา ความชอบ/ไมชอบ skill level ของเขา response กบ event อยางไร activity เปนอยางไร

3.การ design command hierarchy คอ user จา/ทางานอะไรhierarchy ของ command เปนอยางไร ไปกระดบ อยาใหลกมากนก ( <= 3 menu) & command ทใชบอย ควรอยใน list แรก ๆ

HIC

Page 44: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

47

4.design detail interaction between user and system ตองการ ภาพ ส เสยง หรออะไรท high technology หรอไม นอกจากนนม criteria ดงน

- step ในการทาไมมากนก (จานวน mouse click , key stoke)- no dead air ชวงท system ทาอะไรอยควรม feedbackใหuserทราบ

- ควรม undo เรยกสงททาครงสดทายคนได - user ไมตองจดจาอะไรมากนก จาทงายๆ ทคนเคย - ใชเวลาเรยนรนอย - สวยงาม นาใช

5. design HIC classes necessary to manage the interaction design class ตางๆ เพอ manage interaction

เชน windows : box button list .. , ใช penbase etc

6. continue prototyping user ทดลองใช เพอดวา HIC ทเรา design ถกตอง & ตรงตามทตองการ

HIC

Page 45: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

48

Check Campaign Budget

Use Case Prototype

In this prototype, Clients and Campaigns are selected in drop-down lists

ตวอยางHIC

Page 46: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

49

Check Campaign Budget

Use Case Prototype

Using a treeView control…

ตวอยางHIC

Page 47: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

50

Check Campaign Budget

Use Case Prototype

Using a separate look-up window

ตวอยางHIC

Page 48: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

51

Future trends in human interfaces

ตอนนเปน graphic user interface ม short and notation &

font ตางๆ มากขน

อาจเปน penbase touch screen device ใหม ๆ

HIC

Page 49: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

52

นอกจากน Designer ตองเตรยม สาหรบความตองการของ user

- complete customization ตรงตามท user ตองการ

- bite-size user interface คอแมจะม command มากมาย แต user

จะเหนเฉพาะทเขาใช

- intelligent user interface อยใน background คอย monitor สงท

user ทา ถาทาผดบอยๆ กจะม warning เตอน ใหคาแนะนา

- intelligent interface คอย monitor พฤตกรรมของ user ทเปน

pattern

HIC

Page 50: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

53

6.3.3 Task management component (TMC)Task คอ process ทม resource ของมนเอง และเปน

asynchronous process คอ เวลาไมเกยวของถาใครสง msg.มา

- หากพรอมกจะทางานนน

- หากกาลงทาอยางอนอย งานนนกรอไป ถาพรอมถงจะทา

ในขณะท obj. (คนปลก) ท สง msg. มากทางานอยางอนตอไดเลย

เพราะฉะนน task คอ asynchronous processทม resourceของมนเอง

และ process คอ stream ของหลายๆ activity

สรป task คอ service ของ object

อาจม service หนงแยกออกมาเปนหลายๆ task เพอทาให service นนเรวๆ

PDC HICDMC TMC Next page

6.3 Object-oriented design architecture

อธบาย Task

Page 51: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

54

System ทตองม task management ระบบนนตองเปน concurrency

อาจม multi processor หรอ single processor

-system ท monitor sensor (device) หลายๆ ตว จงตองเปน

multi-task และ concurrency

-ระบบ ทตองทาหลายๆ user interface

หาก hardware เราม multi processor เราควรทา program เปน

multi-tasking เพอ performance ทด

เหตทตองม task management เพราะวาเราตองการ concurrency

Ok back

TMCConcurrency is the notion of multiple things happening at the same time

Concurrency-systems can do more than one thing at a time.

Page 52: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

55

strategy ในการทา task management

1. identify event driven tasks

event driven tasks เปน passive class คอ class ทมใครมา

interrupt โดยอาจสง data หรอ อะไรมากตาม เมอtaskนรบคา

มากทาการ process หรอสงใหคนอน หรอทางานอะไรกตาม ทา

เสรจกหลบตอ ซง class พวกนเปน class ทคอย monitor device

อนๆ นนเอง

2. identify clock-driven tasks

clock-driven tasks เปน class ทถกปลกเปนชวงเวลา ถง

เวลากถกปลกมาทางาน ทาเสรจกหลบตอ จะม active process

คอย monitor วาถงเวลาหรอยง

TMC

1.

2.

Page 53: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

56

3.identify priority task and critical task

critical task เปน class ท critical ตอความสาเรจหรอ

ลมเหลวของ system จะคอย isolate task อนๆ แยก processing ท

จะทาให system ประสบความสาเรจหรอลมเหลว ดงนน

processing เหลานจะเกยวกบพวกทเปน reliability constraint

ทงหลาย

critical task จะม high criticality กบ ธรรมดา

สาหรบ priority task จะแบงเปน

-high priority task เปน task ทคอย isolate task อน ตอง

ทางานใหเสรจภายในระยะเวลาเทาไร (ม time constraint)

-low priority

TMC3. 4.

Page 54: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

57

4.identity coordinator

ทาหนาทประสานงานระหวาง task ตางๆ แตการม

coordinator เปนการเพม overhead ใน system เพราะวา เปน

ตวคอยดคอยปลกใครตองทากอน ซงมนก take time ดวย แต

หากไมม coordinator task ตองสมพนธกนเอง ใครปลกใคร

ดงนน จะทาให encapsulate หายไป (จง trade off ระหวาง

overhead กบ encapsulate)

TMC

5.

Page 55: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

58

5. challenge each task

แนใจวา task แตละ task meet criteria ทจะเปน task

(event driven task , clock driven task , critical task, priority

task , coordinator task) เราพยายาม minimum จานวน task

เพอการ design จะไดไมยงยาก

TMC

Page 56: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

59

6.define each task

define แตละ task วาคออะไร ตงแต task name ,

constraint ของ task , coordinator อยางไร , communication

กบคนอนอยางไร

-coordinate คอ ถกปลกอยาไร ถาเปน event กอธบาย

วาอะไร trigger, ถาเปน clock กอธบายถง time

interrupt

-communicate อยางไร รบคา data จากไหน , สง data

ไปไหน

TMC

Page 57: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

60

สรป Task Management ComponentTask คอ service ของ object อาจม service หนงแยกออกมาเปน

หลาย ๆ task เพอทาให service นนเรวๆTask Management Component-asynchronous process ทม resourceของมนเอง

และ process คอ stream ของหลายๆ activity

ทาไมตองม TMC ขนกบ ลกษณะงาน -monitor sensor (device) เพอ performance ทด

จะทาTMC เครอง(HW)ตอง support : เปน concurrency (multiprocessor/single processor)

-ประเภท task : event driven , clock-driven , priority , critical , coordinator

Ready –gogoNot ready..wait

TMC

Page 58: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

61

6.3.4 Data management component (DMC)

เพอเกบ data ลง storage & retrieve data จาก storage

หากเราใช OODBMSจดการobject เราก connect OODBMS -กได DMC

การจดเกบขอมล

-extended มาจาก relational database

แลวสราง on top relational DB คอพนฐานจรงๆ เกบแบบ relational

แต user มองเหนเปน OO (คอ map จาก OO ไปท relational)

-extended มาจาก OOPL

เชน ภาษา smalltalk เนองจาก OOP ไมมการ save object ลง file

จงเขยน on top smalltalk ทม facility พวกน

PDC HICDMC TMC

Save-OODBMS-Relational database-Extended OOPL -File

6.3 OOD Architecture

1.

2.

3.

Page 59: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

62

การม DMC มขอด/ขอเสยอยางไร

การทจะ save ตวเองไดตองสง message ทจะ save ไปให DMC

แลว DMC ถงจะไป save อกท

ซงกม overhead แตหากไมม component น ใหทกๆ object save ตวเอง ,

retrieve ตวเอง กไมม overhead

แตหากเปลยนวธการเกบหรอเปลยนอะไร (fileRelational:

MySQL) จะกระทบ จงแยกสวนนออกมาเปน component ซงการ

เปลยนแปลงจะกระทบเฉพาะ component เทานนไมกระทบ problem

domain

DMC

PDCHIC DMC

Page 60: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

63

DMC แบงเปน 2 สวน – data layout – design service1.data layout การ design data layout ขนกบวาเราจะเกบแบบไหน

1.1 define data layout สาหรบ flat file (เกบลง file ธรรมดา)

- ทา first normal form (no repeat group) list 1 class/table

และ list attribute ออกมา ทาใหเปน 1 NF หากมบาง attribute ท

complex กแตกออกมา จนได table ทอยใน 1 NF แลว define 1

file/table

-ด performance & storage ทตองการ

เนองจากเราม gen-spec. object หนงตอง access อยางนอย 2 file

เชน

DMC

2.1.

OK เมอตองแยก DMC สงทตองทาหรอพจารณามดงน

Page 61: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

64

Person-name-address

Owner Clerk- salary

เรา get inf. Clerk ตอง get > 1 file

ดงนน performance อาจไมด

อาจตองยบ person กบ owner เปน file เดยวกน

ยบ person กบ clerk เปน file เดยวกน ดงนน ม 2 file

Flat file 1 class/table จากตย. 3 class 3Tables

DMC

Page 62: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

65

-การด storage

อาจมบาง attribute เกดจากการคานวณของ attribute อน

เราอาจตด attribute นทงได แตตองม process ในการคานวณ

attribute ทตดทงน สรป หากเกบ fileธรรมดา

-1NF - performance & storage ยบตาราง(gen/spec)ปรบ attr.

1.2 define layout สาหรบ relational

- define table อยางนอยทสด third normal form2NF – อยในรป 1 NF & non key attribute ตองไม partially dependency on key คอ ขนอยกบบาง key)3NF – อยใน 2 NF & nonkey attribute ตองไม transitively dependency)

DMC

Data layout -file -relational

Page 63: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

66

ขนแรก list เปน 1 class/table

แลวอาจแตกเปน 2 , 3 table ใหอยในรป 3 NF

แลว map เปน table ใน relational database

แตเวลา access object ใน class หนง อาจตอง join หลาย table

ถงจะได inf. ครบ 1 object ซงเปนขอเสย

-ปกตRelational ทา3NF(คอ เรมจาก 1 table/class , 1 attribute/columnแตก 3 NF)

(แตถา attribute complex เราอาจตองแตก attribute เปนหลายๆ column ซง

แตละ column เปน 1 simple attribute)

DMCOk ทา DMC 1.2 Relational DB 3NF

Page 64: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

67

Objects as a Table

• get to First Normal Form, break out the repeating groups

YPSC

ขยาย/เตม ขอมลใหเตม next p.

SMHL SMHL

DMCตย.

Page 65: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

68

First Normal Form

DMC

Page 66: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

69

Second Normal Form

แยก code campaign code Location

ไดตาราง campaign

ตาราง Location

ร locationMgr –ร locationMgrTel

พจารณาตอ

Next p

DMC

Page 67: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

70

Third Normal Form

สรป- relational ได 4 ตาราง

DMC

Page 68: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

71

- primary key ใน relational

เปน field ( attribute) หรอ group ของ field(attribute) ทจะ

unique identify

แตหากใช Object DBMS ม object identifier ซงม machine generate

object identifier ใชเปน primary key และ identifier นuserจะมอง

ไมเหน

-แตละ object คอ 1 row ใน table

-ความสมพนธระหวาง object หรอ class กจะเปนอก tableเฉพาะความสมพนธ 1:M หรอ M:M เทานนทเราจะ create table

ใหม โดยนา key ของ class A , key ของ class B มาเปน attribute

ใน table ใหม เชน

DMC

Page 69: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

72

1 1 : *Owner Car

OwnerID name Addr Tel ObjID รน

Owner 1 table Car 1 table

OwnerID ObjID

ความสมพนธกสรางอก 1 table

-ถาเปน 1:1 กนา owner ID ไปใสใน obj.ID หรอกลบกน ใสขางใดขางหนง

หรอใสทง2 ขางกได

DMC

แตกตางกบวธ ER di. ??หรอไม

Page 70: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

73

2. design serviceเพอ retrieve data , save data , update คา

ถาใช DBMS กใช command ไดเลย หากไมมกสราง ซงอยใน DMC

ดงนน ใน DMC กม class ตางๆ ทเราจะเกบลง file(persistence) อยางนอยๆ ตองม 3 method

- method : create new record หรอ create new row เพอเวลาobject ใน problem domain สง message มาให save object ใหมmethod นจะทางาน- retrieve record ไปอาน record ทถกตอง- method ทรบ data จาก Problem domain component หรอHuman interaction component หรอ Task management component

DMC แบงเปน 2 สวน – data layout – design service

DMC2.1.

-file-relational

Page 71: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

74

บทท 6 Designsystem design & detailed design

6.1 สงทเราตองการจาก notation ทเรา document :visibility persistence exception..

6.2 objective ของ object-oriented design :increase improve maintainประโยชน+ขอด

6.3 Object-oriented architectureProblem domain component (PDC)Human interaction component (HIC) input/output Task management component (TMC) Data management component (DMC)-data layout-design service

6.4 Criteria ทใชในการออกแบบ *now6.5 ภาษาทใชในการ implement

PDC HICDMC TMC

Page 72: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

75

6.4 Criteria for good design

Criteria ทจะดวา design ด/ไมดเราจะดวา total cost ของ system ทงหมดเปนอยางไร ตงแต

analysis cost , design cost , programming cost , test , debug, h/w,

operation etc. เปน cost ตาง ๆ ทเกดขนในการทาระบบ

Criteria ทจะดวา design ด/ไมด

ม 2 concept ใหญ ๆ คอ

-Coupling ผกตดกน

-Cohesion ผสานกน

และ reuse

Page 73: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

76

Coupling Coupling describes the degree of interconnectedness

between design components

คอ degree ของการม interdependency หรอ

interconnection วาผกตดกนมากนอยแคไหน

ลกษณะทตองการในแงของ coupling คอ หากเรา

เปลยนแปลง สวนใดสวนหนงของการ design ควรจะ

effect ตอสวนอน ๆ นอยทสด

Page 74: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

77

coupling ม 2 ลกษณะ

- interaction coupling เราตองการตา ๆ คอ Loosely couple

ซงความหมาย คอ ความสมพนธระหวาง object โดยผาน msg. นน

มการสง msg. จาก obj. obj. มากนอยแคไหน

หากมาก 2 obj. tightly couple ไมควรแยกเปน 2 obj. น ตรงน ดเฉพาะทไมใชสวนของ class hierarchy (คอไมได

อยในสวนของ gen-spec , composition) การด msg. connection เรา

ตองการ minimize couple ตองการใหสง msg. กนนอย ๆ

-interaction coupling -inheritance coupling

Page 75: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

78

นอกจากน ตว msg. ตองไม complex ม parameter ไมมาก

และ object มลกษณะเปนทางผานหรอไม

ทางผาน

A B C

หมายความวา A สง msg. ให B พรอม inf. บางอยาง

ผาน Parameter แลว B สง msg. ให C โดยใช inf. นนผาน

ให C โดยท B ไมไดทา processing หรอใชประโยชน กบ inf. ท A

สงมาใหเลย B กเปนแคทางผานเทานน เราไมตองการลกษณะ

เชนน

Page 76: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

79

- inheritance coupling คอความสมพนธ การผกตดกนระหวาง subclass/superclass เราตองการ tightly couple เพราะเรา

ตองการความสมพนธ ISA สงทเปน specialization นนเปน

กรณพเศษของ generalization จรง ๆ

specialization ISA generalization

เราด - subclass inherit attribute หรอ method มาแลว

ใชหรอไมใช มากนอยแคไหน เหมาะสมกบตวมนหรอไม

- inherit ลงมาแลวไมสมพนธกบเลยตอง redefine ใหม

ไมใชสงทเราตองการ

∴ coupling ระหวาง superclass–subclass เราตองการสง ๆ

Page 77: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

80

Inheritance Coupling

Vehicle

decription serviceDate maximumAltitude takeOffSpeed

checkAltitude() takeOff()

LandVehicle

numberOfAxles registrationDate register()

Inheritance Coupling describes the degree to which a subclass actually needs the features it inheritsfrom its base class.

Poor inheritancecoupling as

unwanted attributes and operations are

inherited

เกยวกบเครองบน

-interaction coupling->loose

-inheritance coupling ->tight

Page 78: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

81

สรป Coupling describes the degree of interconnectedness between design components

Coupling – degree ของ interconnection

• Interaction coupling (loosely couple) –not hierarchy –>associate

นอกจากน

msg. ตองไม complex ม parameter ไมมาก

และ object ไมใชเปนแคทางผาน

• Inheritance coupling (tightly couple)

Page 79: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

82

Cohesion คอ degree ของความสมพนธกน วาสมพนธกนมาก

นอยแคไหนตางจาก coupling ตรงทวา cohesion ดเปน group

group หนงสมพนธกนอยางไร มากนอยแคไหน

การดเปน group

อาจดวา class หนงๆobject ใน class สมพนธกนมากนอยแคไหน

หรอ subprogram นน code ใน subprogram นน สมพนธกนมากนอย

แคไหน ทาก function จง carry out ออกมาได function เดยว

หรอ carry out ออกมา ตองทาหลาย ๆ function

คอ Cohesion ดเปนกลมเปนกอน วากลมนทาแลวออกมา

ไดอยางเดยวกนจรงหรอไม คอ inter-relate หรอ togetherness

(แต coupling นน ดเปน คๆ )

Page 80: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

83

cohesion ม 3 ระดบ

level 1. Service /operation/ method cohesion

เปน cohesion ใน method เราตองการ คอ 1 method หรอ 1

service ทา 1 อยาง ( 1 method : 1 function) ไมตองการสงท

complicate ใน method นน อานชอแลวสอวา method นทาอะไร ใน

method ไมควรมลกษณะ if-then-else

หรอ CASE statement ทมอะไรซอนอยมากมาย

level 2. Class cohesion

ระหวาง attribute กบ method ตองสมพนธกนอยางมาก คอ

ตอง encapsulate กน

ทก attribute ตองถกใช ทก method ตองถกใช

จะไมม attribute หรอ method ไหนเกนมา

Page 81: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

84

Operation Cohesion

Lecturer

lecturerName lecturerAddress roomNumber roomLength roomWidth calculateRoomSpace()

{return roomLenght* roomWidth;}

Good operation cohesion but poor class cohesion

ระดบ method –ไม complicate :ด

ระดบ class – attribute&method ตอง encapsulate

Page 82: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

85

level 3. Generalization-Specialization Cohesion

cohesion ใน class hierarchy คอ ระหวาง subclass-

superclass ตองม cohesion สง คอ subclass นนตองเปน

specialization ของ superclass จรง ๆ

Page 83: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

86

Poor Specialization Cohesion

Address

number street town county country postCode

Person

personName age gender

Company

companyName annualIncome annualProfit

Specialization Cohesion addresses the semantic cohesion of inheritance

hierarchies

Page 84: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

87

Improved Structure

Address

number street town county country postCode

Person

personName age gender

Company

companyName annualIncome annualProfit

lives at is based at

Improved structure usingAddressclass.

Page 85: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

88

Coupling – degree ของ interconnection– Interaction coupling (loosely couple)– Inheritance coupling (tightly couple)

Cohesion – degree ของความสมพนธดเปน group -inter relate , togetherness– Service/operation/method cohesion --ไมซบซอน– Class cohesion – attribute&method– encapsulate– Gen/spec cohesion –สงๆ เปนจรงๆsubclass ISA superclass

สรป 6.4 Criteria ทจะดวา design ด/ไมด ม 2 concept ใหญ ๆ คอ

CouplingCohesion

+ reuse

Page 86: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

89

นอกจากนยงมCriteria ทนามาชวยพจารณาวาท design มานน ด/ไมด คอ

Reuse

มการใช reusable component มากนอยแคไหน & การใช

reuse มความสาคญดงน - ทาให productivity สงขน เพราะวาเรา reusable component สงท

ตอง implement มไมมาก งานเสรจเรวขน

- quality ของงานดขน เพราะวา component ตางๆ หลากหลายคน

นาไปใชกเจอ bug ตางๆ กแกไข ดงนน ยงใชมาก quality กยงด

Page 87: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

90

level ของ reusabilitylevel 1 reuse code level 2 reuse design result level 3 reuse analysis resultlevel 4 object-oriented component librarylevel 5 designware

Page 88: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

91

level ของ reusability ม 5 level

level 1 reuse code -copy code เขามาใสใน program เราเลย ซงวธนไมด เพราะวาเราไป cut & paste

มา ม bug อะไรเราแกไข แต original ไมถกแก คนอนใช กเจอแบบเดยวกน

-ใช include file , subroutine , macro ใน library เรา include แลวหาก original

เปลยน เราก recompile ใหม

-inheritance เปน reusability เพราะวา inherit มาจาก superclass

-binary link ปกตเครอง mainframe compile-link-load module-run หากมการ

เปลยนแปลง subroutine เราไป link ใหม (ไมตอง compile ใหม) เพอจะได load

module

-execution-time invocation สาหรบ interpreter เทานน เพราะวา การ binding

ระหวาง subroutine ใน library กบ main program จะ bind ตอน dynamic binding

execution time invocation

Page 89: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

92

level 2 reuse design result เรานา design ของระบบเดม มาใชในการ

implement บนคนละ environment

เชน จาก batchonline

level 3 reuse analysis result นาผลลพธจากการ analysis มา design ใหม

เนองจากอาจมการเปลยนเครองใหม ภาษาใหม OS ใหม ม feature ทดกวา

level 4 object-oriented component library : เรา reuse สงทมอยแลวใน library

level 5 designware

analysis ตรงกบของเราหรอไม จะ customize ตรงไหนหรอไม

design model ตรงกบของเราหรอไม จะ customize ตรงไหน

หรอไมเมอเรา customize แลวจะ gen. code ใหเราเลย ซงจะงายและสบายกวาแบบเกา

Page 90: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

93

6.5 ภาษาทใช implement มอะไรบาง-ควรเลอกภาษาไหน

-ภาษาทเรยกวา OOPL ควรเปนอยางไร , ม feature

อะไรบาง

-ภาษาไหนทไมใช OOPL

-แมวาเราจะ analysis ,design เปน OO แตเราอาจ

implement โดยใช third generation language เชน C ,

Pascal หรอจะใช OOPL กได

Page 91: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

94

Object-oriented programming language

ควรม feature อยางนอย 5 อยาง

1.ทาอยางไรถงจะ create class , create object

ม feature ในการ encapsulate attribute กบ operation เขาดวยกน

นอกจากนกสามารถระบ visibility(private , public คออะไร)

mechanism ทเราตองทาได เชน จะ create object อยางไร จะ delete

อยางไร

2.ทาอยาไรถงจะ create gen-spec. ได

Page 92: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

95

ควรม inheritance อยางนอย single inheritance แตถาใน analysis ม

multiple inheritance

ทางแก

1). แยกแลวสรางความสมพนธ

2). หายไปเลย เอาไปไวขางในเปน attribute/method ลบทงอนใด

อนหนง(ไมแนะนา)

3).นามาเปน composition ของอกอนหนง ซงตองดวา class ไหน

major กวากน

Person

Owner

Role

clerk

Person

ClerkOwner

2).

Page 93: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

96

1). split เปนหลายๆ single inheritance แลวทา connection กน

Person

ClerkOwner

Role

Clerk RoleOwner Role

Person

ClerkOwner

Role

Clerk RoleOwner Role

หรอ

Page 94: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

97

Person

Owner

Clerk

Role

OwnerRole ClerkRole

3).ถาตองการเกบ gen-spec ของ person ทแบงเปน owner กบ clerk

มากกวา ทจะเกบ role ทเปน owner_role กบ clerk-role เรานา role

มาเปนสวนประกอบของ person แลวคอยแตกเปนอะไร

Page 95: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

98

3.ทาอยางไรถงจะ create composition structure หรอ whole-part structure

ตองม class ทเปนลกษณะท containment

class (class ทม class อนอย ขางใน) อาจเปน

ลกษณะของ pointer หรออะไรกแลวแต

4.จะอธบาย attribute อยางไร ดวา- visibility มกประเภท ทสามารถจะ

represent instance connection ได

Page 96: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

99

5.จะอธบาย method (operation , service) อยางไรคอจะม feature ของ polymorphism หรอ dynamic binding

หรอไม (คอ polymorphism คออะไร แลวทาไมถงเปน dynamic

binding

polymorphism คอ สง message เดยวกนไปให object ของ

class คนละ class จะได action ทไมเหมอนกนได

และเปน dynamic binding หมายถง message น invoke

method ไหน determine ไดตอน run time

(หาก determine ไดตอน compile time ถอเปน static binding)สรป OOPL-create class create object – create gen/spec

– create composition – attribute (visibility) -method

polymorphism dynamic binding

Page 97: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

100

การเลอก OOPL ภาษาไหนขนกบ

-OOPL ไหนทใชกนมาก

-Cost เปนอยางไร ( cost ในการ develop system)

-Class library : ใหญ กเลอกใช reusable component ไดมาก

ก develop ไดเรว cost กตา

-Environment ของภาษา

Debugger

Browser เพอ browse ดวาม class อะไรบาง

Configuration management เปนตวทคอยดวา หาก

มการเปลยนแปลง class ใด การเปลยนนจะไป

effect ตอใครบาง

-เครองทใชเปนประเภทใด

Page 98: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

101

TestingTesting Objectives

“Testing is the process of executing a program with the intent of finding errors” [Myers 1979]

เราจะออกแบบอยางไรเพอคนหา error ใหไดมากทสด

Test Case Design2 approaches:

White-Box TestingBlack-Box Testing

Page 99: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

102

Who Tests the Software?

• Understand the system,

but will test “gently and,

is driven by “delivery”

• Must learn about the

system, but will attempt

to break it and, is driven

by quality

developer Independent tester

Page 100: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

103

OO testing• Unit testing, integration testing, validation and system testing.

-Unit testing ใชทง white box + black box

การทดสอบ class hierarchy จะยากกวา-integration testing-validation

จะเรยนในบทท 7

Page 101: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

104

testing ใน OO จะยงยากกวาการ test ใน structure programming

เพราะวา

-polymorphism จะทาใหเรา debug ยาก เพราะวา เราไมรวา

message นไป invoke ตวไหน

-inheritance ทาใหเรา debug ยาก , test ยาก เพราะวา

subclass inherit มาแลวสามารถทจะ overwrite อะไรกตามท

มน inherit มา ดงนน method ทเรา test กบ superclass นแลว

work แต inherit ลงไปแลว เราไมแนใจวาท subclass work

จงตอง test ทก class ใน hierarchy

Page 102: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

105

OO testing ม tools อะไรมาชวย ในการทา debugging

debugger ทคอยคนวา location ของ bug อยทไหน และเปน bug

แบบไหน โดยเฉพาะอยางยง ถาม concurrency (คอ method

เดยวกน run พรอมกนหลายๆ processor) ตองม debugger มา

ชวยในการ locate วา bug เกดขนตรงไหนและเปน bug ประเภท

ไหน

configuration management คอย locate วา ถามการเปลยนแปลง

ท class น class ใดบางจะกระทบกระเทอน

Page 103: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

106

Implementation Strategies

Direct changeover

Parallel running

Phased changeover

Time

Old system

New system

Old system

New system

Old system

New system—Phase 1

New system—Phase 3

New system—Phase 2

จบ บทท 6 Design

maintenance

Page 104: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

107

บทท 6 Designsystem design & detailed design

6.1 สงทเราตองการจาก notation ทเรา document :visibility persistence exception..6.2 objective ของ object-oriented design :increase improve maintain

ประโยชน+ขอด6.3 Object-oriented architecture

Problem domain component (PDC)Human interaction component (HIC) input/output Task management component (TMC) Data management component (DMC)

6.4 Criteria ทใชในการออกแบบ6.5 ภาษาทใชในการ implement

Page 105: Object-oriented design 2. Software life-cycle · PDF file1 Object-oriented design 1. Introduction 2. Software life-cycle model. 3. OO analysis -structure analysis. 4. UML : Notation

108

Project proposal : Problem domainUML

Structure analysisActivity diagram –Overall Business work flow

Use case diagram-requirementClass diagram

Behavior analysissequence diagramcollaboration diagram

statechart diagram classactivity diagram : method

Implementcomponent diagramdeployment diagram

activity diagram: use case

equivalence

Design : UML เดม แตเพมรายละเอยดมากขน interface , data managementPrototype

ไล Source code ดclass

Project ททาสง