• No results found

Software Design

N/A
N/A
Protected

Academic year: 2020

Share "Software Design"

Copied!
46
0
0

Loading.... (view fulltext now)

Full text

(1)

© SERG

Software Design (UML)

Software Design

Static Modeling using the

Unified Modeling Language (UML)

Material based on

(2)

© SERG

Software Design (UML)

Classes

ClassName

attributes

operations

A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics.

(3)

© SERG

Software Design (UML)

Class Names

ClassName

attributes

operations

(4)

© SERG

Software Design (UML)

Class Attributes

Person

name : String address : Address birthdate : Date ssn : Id

An attribute is a named property of a

class that describes the object being modeled. In the class diagram, attributes appear in

(5)

© SERG

Software Design (UML)

Class Attributes (Cont’d)

Person

name : String address : Address birthdate : Date / age : Date ssn : Id

Attributes are usually listed in the form:

attributeName : Type

A derived attribute is one that can be computed from other attributes, but doesn’t actually exist. For example, a Person’s age can be computed from his birth date. A derived attribute is designated by a preceding ‘/’ as in:

(6)

© SERG

Software Design (UML)

Class Attributes (Cont’d)

Person

+ name : String # address : Address # birthdate : Date / age : Date - ssn : Id

(7)

© SERG

Software Design (UML)

Class Operations

Person

name : String address : Address birthdate : Date ssn : Id

eat sleep work play

(8)

© SERG

Software Design (UML)

Class Operations (Cont’d)

PhoneBook

newEntry (n : Name, a : Address, p : PhoneNumber, d : Description) getPhone ( n : Name, a : Address) : PhoneNumber

(9)

© SERG

Software Design (UML)

Depicting Classes

Person

name : String birthdate : Date ssn : Id

eat() sleep() work() play()

When drawing a class, you needn’t show attributes and operation in every diagram.

(10)

© SERG

Software Design (UML)

Class Responsibilities

A class may also include its responsibilities in a class diagram.

A responsibility is a contract or obligation of a class to perform a particular service.

SmokeAlarm

Responsibilities

-- sound alert and notify guard station when smoke is detected.

(11)

© SERG

Software Design (UML)

Relationships

In UML, object interconnections (logical or physical), are modeled as relationships.

There are three kinds of relationships in UML:

• dependencies

• generalizations

(12)

© SERG

Software Design (UML)

Dependency Relationships

CourseSchedule

add(c : Course)

remove(c : Course)

Course

A dependency indicates a semantic relationship between two or more elements. The dependency from CourseSchedule to

Course exists because Course is used in both the add and

(13)

© SERG

Software Design (UML)

Generalization Relationships

Person

A generalization connects a subclass to its superclass. It denotes an

inheritance of attributes and behavior from the superclass to the subclass and indicates a specialization in the

subclass

of the more general superclass. Extended by

(14)

© SERG

Software Design (UML)

Generalization Relationships (Cont’d)

Student

UML permits a class to inherit from multiple superclasses,

although some programming languages (e.g., Java) do not permit multiple inheritance.

TeachingAssistant

(15)

© SERG

Software Design (UML)

Association Relationships

If two classes in a model need to communicate with each other, there must be link between them.

An association denotes that link.

(16)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can indicate the multiplicity of an association by adding

multiplicity adornments to the line denoting the association.

The example indicates that a Student has one or more

Instructors:

Instructor Student

(17)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

The example indicates that every Instructor has one or more

Students:

Instructor Student

(18)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can also indicate the behavior of an object in an association (i.e., the role of an object) using rolenames.

Instructor Student

1..* 1..*

(19)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can also name the association.

Team

Student membership

(20)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can specify dual associations.

Team Student

member of 1..*

president of

1 1..*

(21)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can constrain the association relationship by defining the

navigability of the association. Here, a Router object requests services from a DNS object by sending messages to (invoking the operations of) the server. The direction of the association indicates that the server has no knowledge of the Router.

(22)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

Associations can also be objects themselves, called link classes

or an association classes.

Warranty Product

Registration modelNumber

(23)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

A class can have a self association.

LinkedListNode

next

(24)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

We can model objects that contain other objects by way of special associations called aggregations and compositions.

An aggregation specifies a whole-part relationship between an aggregate (a whole) and a constituent part, where the part can exist independently from the aggregate. Aggregations are denoted by a hollow-diamond adornment on the association. Has, Owns

Car

Engine

(25)

© SERG

Software Design (UML)

Association Relationships (Cont’d)

A composition indicates a strong ownership and coincident lifetime of parts by the whole (i.e., they live and die as a whole). Compositions are denoted by a filled-diamond adornment on the association.

Window Scrollbar Titlebar Menu 1 1 1 1 1

(26)

© SERG

Groups

• Whenever we create a subclass, we are

defining a new group of objects, that is a

subset of the superclass’ group

• To be even more complete, when we define

inheritance, we usually use keywords to

(27)

© SERG

Overlapping/Disjoint Groups

• Overlapping/Disjoint

– Overlapping: Groups are overlapping if there

are objects that are members of both groups.

– Disjoint: Groups are disjoint if there are no

(28)

© SERG

Overlapping Groups

• Overlapping/Disjoint

– Example: Say we have a superclass called

‘Movie’

– Say we have two subclasses of ‘Movie’ called

‘Comedy’ and ‘Action’

– Since it is possible for a movie to have both

action and comedy, the two groups are

(29)

© SERG

Overlapping Groups

Comedy Action

Movies

(30)

© SERG

Disjoint Groups

• Overlapping/Disjoint

– Example: Say we have a superclass called

‘Book’

– Say we have two subclasses of ‘Book’ called

‘Paperback’ and ‘Hardcover’

– Since a book is either a paperback or a

(31)

© SERG

Disjoint Groups

Book

Paperback Hardcover

(32)

© SERG

Disjoint Groups

Hardcover Paperback

(33)

© SERG

Complete/Incomplete Groups

• Complete/Incomplete

– Complete: The groups listed contain all

possible objects that belong to the superclass’

group

• I.e. No more disjoint subclasses can be defined

(34)

© SERG

Complete Groups

• Complete/Incomplete

– Example: Consider our superclass ‘Book’ with

its subclasses ‘Hardcover’ and ‘Paperback’

– Are there any other kinds of book?

(35)

© SERG

Complete Groups

Book

Paperback Hardcover

(36)

© SERG

Complete Groups

Hardcover Paperback

(37)

© SERG

Incomplete Groups

• Complete/Incomplete

– Example: Consider our superclass ‘Movie’ with

its subclasses ‘Comedy’ and ‘Action’

– Are there any other kinds of movie?

(38)

© SERG

Incomplete Groups

Movie

Comedy Action

(39)

© SERG

Incomplete Groups

Action

Movies

Comedy

(40)

© SERG

Software Design (UML)

Interfaces

An interface is a named set of

operations that specifies the behavior of objects without showing their inner structure. It can be rendered in the

model by a one- or two-compartment rectangle, with the stereotype

<<interface>> above the interface name.

(41)

© SERG

Software Design (UML)

Interface Services

Interfaces do not get instantiated. They have no attributes or state. Rather, they specify the services offered by a related class.

<<interface>> ControlPanel

(42)

© SERG

Software Design (UML)

Interface Realization Relationship

<<interface>> ControlPanel

VendingMachine

A realization relationship connects a class with an interface that supplies its

behavioral specification. It is rendered by a dashed line with a hollow triangle towards the specifier.

specifier

(43)

© SERG

Software Design (UML)

Interfaces

A class’ interface can also be rendered by a circle

connected to a class by a solid line.

File

outputStream inputStream

FileWriter

{file must not be locked}

FileReader

(44)

© SERG

Class Diagram for Univ. Courses

Software Design (UML)

Department Course Professor Instructor Adjunct 1..* 1..* offers 0..3 1 teaches

1..* assigned to 1..* 0..1

(45)

© SERG

Software Design (UML) 45

School Department

Student Subject Instructor

1…* * member * 1..5 attends 1..3 1..* teaches 1..* 1 1 1..* has 1..* 1..* assignedTo offeres

(46)

© SERG

Banking System Class Diagram

References

Related documents

Abstract— The present study investigates the effect of inclusions on the shape and size of crack tip plastic zones in engineering materials subjected to static loads by

Favor you leave and sample policy employees use their job application for absence may take family and produce emails waste company it discusses email etiquette Deviation from

An individual domain instance of this property can have zero, one or more instances of this property, but an individual range instance must be referenced by exactly one instance of

Walaupun pada kadar masukan berbeza, butiran enapcemar aerobik telah berjaya dibentuk untuk perawatan air sisa berkadaran tinggi

In order to characterise the dynamics within an organisation, dynamic properties for each of the elements of an organisation structure have to be specified: for

At the risk of over-simplifying, inflation targeting central banks in the industrial world are by far the most reluctant to wield this instrument while monetary authorities in

The re-structure within Planning and Economic Development Services, of which Building Standards is a part, and the appointment of the new Head of the Planning and Economic

Since the signature is extracted from the acceleration signals, the data collection stage is also an acceleration data processing stage, and since this is the operation