Modeling Structure – Class Diagram. Class Diagram.

29
Modeling Structure – Class Diagram
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    289
  • download

    3

Transcript of Modeling Structure – Class Diagram. Class Diagram.

Page 1: Modeling Structure – Class Diagram. Class Diagram.

Modeling Structure – Class Diagram

Page 2: Modeling Structure – Class Diagram. Class Diagram.

Class Diagram

Page 3: Modeling Structure – Class Diagram. Class Diagram.

Operations (behaviors) to fulfill the class’s responsibilities.

Object class name

Attributes

Page 4: Modeling Structure – Class Diagram. Class Diagram.

Steps in Developing a Class Diagram

Identify object classesIdentify associationsIdentify object attributesOrganize object classes using inheritanceDescribe communication using sequence diagramsGroup classes

Page 5: Modeling Structure – Class Diagram. Class Diagram.

Class

attributes

subClass

subClass

operations

Class Diagram

Object

Object

Object

subClass

Page 6: Modeling Structure – Class Diagram. Class Diagram.

Relationships between classes

1. Associations 2. Composition/Aggregation3. Generalization/Specialization

Associations– relationship between classes– E.g, Employee works in Department– Specifies how many instances of one class may

relate to a single instance of another class

• 1-to-1 association • Optional association (0, 1, or many) – Company has President – Customer owns Credit

Card• 1-to-many association • Many-to-Many

association – Bank manages Account – Course has Student

– Student attends Course

Page 7: Modeling Structure – Class Diagram. Class Diagram.

Showing Association                                                   

An Association between two classes is shown by a simple line. It can be given a descriptive name and augmented with the Role played by each class and with the Cardinality of the relationship.

Page 8: Modeling Structure – Class Diagram. Class Diagram.

Associations

Has-capital

One-to-one association

One-to-many association

City

name:String

Workorder

schedule()

StickyNote

x: Integery: Integerz: Integer

*

Country

name:String

[From Bruegge, 2000]

Page 9: Modeling Structure – Class Diagram. Class Diagram.

Many-to-Many Associations

Work on **Mechanics Plane

[From Bruegge, 2000]

Page 10: Modeling Structure – Class Diagram. Class Diagram.

Sample UML Cardinality Notations

Multiplicity Multiplicity

Works for

0..1Has

0..*Makes

UML

Notation Association with Multiplicity Association

Meaning

Exactly 1

1

or

leave blank

DepartmentEmployee1Works for

DepartmentEmployee

An employee works for one and only one department.

Zero or one 0..1 SpouseEmployeeAn employee has either one or no

spouse.

Zero or more

0..*

or

*

PaymentCustomer

PaymentCustomerMakes *

A customer can make no payment

up to many payments.

One or more 1..* CourseUniversityOffers 1..* A university

offers at least 1 course up to

many courses.

Specific range 7..9 GameTeam

7..9Has

scheduled A team has either 7, 8, or 9 games

scheduled

Page 11: Modeling Structure – Class Diagram. Class Diagram.

Composition and Aggregation Hierarchies• Whole/Part Relationships

– Show components of more complex class– Composition is stronger relationship than aggregation

• Composition Hierarchy– Whole and part objects are created, live, die together– Often also has a physical association– Association between instances

• Aggregation Hierarchy– Part objects of aggregate object may be created and deleted independently of aggregate object– Often used for more abstract whole/part relationships than composite objects

Page 12: Modeling Structure – Class Diagram. Class Diagram.

Showing Aggregation                                    

If one class is contained within another a solid diamond is placed on the line next to the containing class. This is termed by value, Class2 it essentially a value within Class1.

If the relationship is a simple aggregation then an empty diamond is used. This is termed by reference, Class1 refers to Class2.

Page 13: Modeling Structure – Class Diagram. Class Diagram.

Kereta

RodaEnjin TempatDuduk

Aggregation Example

Page 14: Modeling Structure – Class Diagram. Class Diagram.

weight

Automobile

serial numberyearmanufacturermodelcolor

drivepurchase

Aggregation Example

Engine

horsepowervolume

onoff

4,6

Wheel

diameternumber of bolts

2,4

Door

openclose

Battery

ampsvolts

chargedischarge

*

Brakelight

onoff

[From Bruegge, 2000]

Page 15: Modeling Structure – Class Diagram. Class Diagram.

• Some classes are similar but not identical – Have some attributes in common, others different

• Common attributes abstracted into generalized class(superclass) – E.g., Account (Account number, Balance)

• Different attributes are properties of specialized class(subclass) – E.g., Savings Account (Interest)

• IS A relationship between subclass and superclass – Savings Account IS A Account

Generalization / Specialization Hierarchy

Page 16: Modeling Structure – Class Diagram. Class Diagram.

‘generalization’ showing inheritance 

                                                                                              

Inheritance is shown by a line from the sub-class to the super-class with an arrow pointing to the super class.

Super class

Sub class

Page 17: Modeling Structure – Class Diagram. Class Diagram.

STAF

NamaAlamatGajiNo.staf

STAFPengeluaran

Kiragajicetakslipgaji

STAFPentadbiran

Kiragajicetakslipgaji

Pengurus

Kiragajicetakslipgaji

Example : Inheritance

Page 18: Modeling Structure – Class Diagram. Class Diagram.

UML Representation of Generalization/Specialization

walk()jump()talk()sleep()eat()etc.()

last namefirst namebirthdategender

Person

enroll()displayGPA()

GPAclassification

Student

lecture()

rank

Teacher

Arrowhead indicatesgeneralization/specializationrelationship

Page 19: Modeling Structure – Class Diagram. Class Diagram.

Inheritance Example

Cell

MuscleCellBloodCell NerveCell

StriateSmoothRed White PyramidalCortical

[From Bruegge, 2000]

Page 20: Modeling Structure – Class Diagram. Class Diagram.

*

Light

offon

1

1

Heater1

Cooler

1

Environmental Controller

Define_climateTerminate_climate

*

1

1

1

1

1

SystemLog

DisplayRecordEvent

Actuator

startUpshutDown

Temperature

Example : Class Diagram

Page 21: Modeling Structure – Class Diagram. Class Diagram.

User

AddressMember#NameSubscribeUnsubscribe

External Reader

Ext. Library NameBorrower

Items BorrowedMaximum Loans

Library Item

No. CopiesShelfNoStatusTitleIssueReturnShelve

Book

AuthorISBNPub. DatePublisher

CAL Package

Distributor

Recorded Media

Course Text

Borrows

Aggregation

Association GeneralizationObject /Class

0..*

Example : Class Diagram

Page 22: Modeling Structure – Class Diagram. Class Diagram.

Summary – Class Relationship

PlanAnalyst

PlanMetrics

Plan

GrowingPlan GardeningPlan

Controller Cooler

Light Heater

FruitGrowingPlan

Food

Vitamin Calorie

analyzes

1..2

1..*

1..231 1

*

* 1

**

* 1

AGGREGATION

ASSOCIATIONGENERALIZATION/ INHERITANCE

COMPOSITION

Page 23: Modeling Structure – Class Diagram. Class Diagram.

<<actor>>Club Member

Member-Date-Of-Last-OrderMember-Daytime-Phone-NumberMember-Credit-Card-Expire-DateMember-Credit-Card-NumberMember-Credit-Card-TypeMember-Balance-DueMember-Bonus-Balance-AvailableAudio-Category-PreferenceAudio-Media-PreferenceDate-EnrolledEmail-AddressGame-Category-PreferenceGame-Media-PreferenceNumber-Of-Credits-EarnedPrivacy-CodeVideo-Category-PreferenceVideo-Media-Preference

persistent

Member Order

Order-NumberOrder-Creation-DateOrder-Fill-DateShipping-Address-NameShipping-Street-AddressShipping-CityShipping-StateShipping-Zip-CodeShipping-InstructionsOrder-Sub-TotalOrder-Sales-TaxOrder-Shipping-MethodOrder-Shipping-&-Handling-CostOrder-StatusOrder-Prepaid-AmountOrder-Prepayment-Method

persistent

Product

Product-NumberUPC-Quantity-In-StockProduct-TypeSuggested-Retail-PriceDefault-Unit-PriceCurrent-Special-Unit-PriceCurrent-Month-Units-SoldCurrent-Year-Units-SoldTotal-Lifetime-Units-Sold

persistent

Video Title

ProducerDirectorVideo-CategoryVideo-Sub-CategoryClosed-CaptionedLanguageRunning-TimeVideo-Media-TypeVideo-EncodingScreen-AspectMPA-Rating-Code

persistent

Audio Tilte

ArtistAudio-CategoryAudio-Sub-CategoryNumber-Of-Units-In-PackageAudio-Media-CodeContent-Advisory-Code

persistent

Transaction

Transaction-Reference-NumberTransaction-DateTransaction-TypeTransaction-DescriptionTransation-Amount

persistent

Member

Member-NumberMember-NameMember-StatusMember-Street-AddressMember-PO-BoxMember-CityMember-StateMember-Zip-Code

persistent

Agreement

Agreement-NumberAgreement-Expire-DateAgreement-Active-DateFulfillment-PeriodRequired-Number-Of-Credits

persistent

Game Title

ManufacturerGame-CategoryGame-Sub-CategoryGame-PlatformGame-Media-TypeNumber-Of-PlayersParent-Advisory-Code

persistent

Title

Title-Of-WorkTitle-CoverCatalog-DescriptionCopyright-DateEntertainment-CompanyCredit-Value

persistent

Member Ordered Product

Quantity-OrderedQuantity-ShippedQuantity-BackorderedPurchase-Unit-PriceCredits-Earned

persistent

Merchandise

Merchandise-NameMerchandise-DescriptionMerchandise-TypeUnit-of-Measure

persistent

Promotion

Promotion-NumberPromotion-Release-DatePromotion-StatusPromotion-Type

persistent

<<actor>>Potential Member

persistent

<<actor>>Past Member

Expiration-Date

persistent

Return

persistent

1..*

1binds

1

0..*

Conducts

1

0..*

Haspurchased

0..10..*

Generates

0..*

1..*

Features

1

0..*

Sold as

0..*

1

Places

1

1..*

Sells

Member Services System Class Diagram

Page 24: Modeling Structure – Class Diagram. Class Diagram.

Class Diagram for KMT Client

Page 25: Modeling Structure – Class Diagram. Class Diagram.

prepare() prepare()

check()

[check=“true”] remove()

needsToReorder()

[needsToReorder=“true”]

enter new

Reorder Item

Delivery Item

Order Entry window

Order Order Line Stock Item

[check=“true”] enter new

Sequence Diagram

Page 26: Modeling Structure – Class Diagram. Class Diagram.

ReOrderItem

itemnumberquantityetc…

DeliveryItem

deliveryadressquantityetc…

Order

orderNumberdateetc…

prepare()

OrderLine

itemnumberquantityetc…

StockItem

orderNumberminQuantitydateetc…

needsToReorder(): boolean

check(): booleanremove()

is_for

prepare()enter new()

enter new()

Page 27: Modeling Structure – Class Diagram. Class Diagram.

Computer: Computer

PrintServer:PrintServer

Printer:Printer

print(file)

User: User

print(filename)

Queue:Queue

[printer free] print(file)

[printer busy] store(file)

Page 28: Modeling Structure – Class Diagram. Class Diagram.

Computer

print(filename)

PrintServer

status(): integer

print(file)

Printer

print(file)

Queue

store(file)

uses

Managed by

Page 29: Modeling Structure – Class Diagram. Class Diagram.

Recap• After studying this chapter we learned

to:– Understand how to structure

requirements with class diagram.

– Explain the element of class diagrams

– Construct class diagrams.