Вы находитесь на странице: 1из 25

COM419

Object-Oriented Modelling

UML: Class diagrams


Ms Anne Hinds

1
Intended learning outcomes
• Define structural (static) models
• Implement modelling methodology
• Identify and use standard UML notation for
structural modelling
• Create simple class diagrams
• Identify opportunities for refinement

2
Key Ideas of Structural Model
• A structural (static) or conceptual model
describes the structure of the data that
supports the business processes in an
organisation.
• The structure of data used in the system is
represented through CRC cards, class
diagrams, and object diagrams.

• CRC stands for Class, Responsibilities, Collaborations.


• Introduced at OOPSLA’89 by Kent Beck and Ward Cunningham.
3
Elements of a CRC card
Front:

Class name:

Description:

Responsibilities: Collaborators:

Back:

Attributes:

Relationships:

Generalization (a-kind-of):

Aggregation (has-parts):

Other Associations:
4
STRUCTURAL MODELS

5
Purpose of Structural Models
• Reduce the “semantic gap” between the real
world and the world of software
• Create a vocabulary for analysts and users
• Represent things, ideas, and concepts of
importance in the application domain

6
Classes
• Templates for creating instances or objects
• Two Kinds
– Concrete
• Used to create objects
– Abstract
• Useful abstractions

7
Attributes
• Units of information relevant to the
description of the class
• Only attributes important to the task should
be included

8
Operations
• Action that instances/objects can take
• Focus on relevant problem-specific operations
(at this point)

9
Relationships
• Generalization
– Create classes that inherit attributes and
operations of other classes
– Is-a-kind-of
• Aggregation
– Relates parts to wholes
– Has-a
• Association
– Miscellaneous relationships between classes
10
CLASS DIAGRAMS

11
Example Conceptual Class Diagram
Person

12
Class Diagram Syntax
A CLASS Class1

-attribute

+operation ()

AN ATTRIBUTE attributeName
/derivedAttributeName

AN OPERATION
operationName ()

AN ASSOCIATION
1..* 0..1
______verb phrase____

13
The Class Diagram
Use of Natural Language
Discard inappropriate candidates
◦ From the nouns in the problem statement
eliminate the
 redundant
 irrelevant - those unrelated to the problem
 vague - ill-defined boundary, very broad in scope
 attributes - things that describe an object
 operations - things that manipulate objects
 implementation constructs - extraneous to real world must be
eliminated from analysis model, needed during design, but not now.

14
Example: problem statement for library
automation system

• Design the software to support the operation of a public


library or group of libraries. The system has a number of
stations and PCs for customer transactions. These stations
are operated by library employees. When a book is
borrowed, the identification card of the client is read. Next,
the station’s barcode reader reads the book’s code. When a
book is returned, the identification card is not needed and
only the book’s code needs to be read.

15
Identify Classes

16
Identify Associations
– Associations correspond to verbs in the problem
statement
– Association = any dependency between two
classes
– From the problem statement
• Employee operates Station
– From tacit knowledge
• Library owns PC

17
Object modelling – data dictionary
• Prepare a data dictionary/ description of each
class
• Name Type Description
Station Class A terminal linked to
a central computer
operated by employees with a
barcode reader.

18
Further specify the semantics of
associations…
Include Multiplicity
How an instance of an object can be associated with
other instances
Numbers placed on association path to denote
minimum and maximum instances that can be
related through the association
minimum number .. maximum number
Numbers specify the relationship from the class at
the far end of the association to the end with the
number
19
Further specify the semantics of
associations…
Relationship Meaning

Exactly one - A department has one


Department Boss and only one boss
1

Employee Child Zero or more – An employee has zero


0..* to many children

One or more – A boss is responsible


Boss Employee for one or more employees
1..*
Zero to one – An employee may have
Employee Spouse at most one spouse
0..1

Employee Holiday Specified range- An employee can


take between 2 and 4 holidays a year
2..4
Multiple, disjoint range – An
Employee Committee employee is a member of 1 to3 or 5
1..3,5 committees
20
Further specify the semantics of associations

Include Multiplicity
Qualifier or Qualified Associations
◦ Usually a name identifies an object within some context;
most names are not globally unique. The context
combines with the name to uniquely identify the object.
◦ A Qualifier distinguishes objects on the many side of an
association. For example, a qualifier bankcode could be
added to distinguish the different banks in a consortium.
Each cash card needs a bank code so that transactions
can be directed to the appropriate bank.

21
Identifying Attributes and operations

• Attributes
– Properties of an individual object
– Usually possessive phrases e.g. the colour of the
car
– Identify from the problem description and domain
knowledge
• Operations
– Define ways in which objects interact

22
Identifying attributes and operations
Borrower

borrowerID
name
address
booksOnLoan
maxBooksAllowed
join()
borrow()
reserve()
return()
changeDetails()
payFine()
leave()

23
How can the class diagram be
refined?

Think Inheritance!

24
Summary
• Class and object diagrams show the
underlying structure of an object-oriented
system.
• Constructing the structural model is an
iterative process involving: textual analysis,
brainstorming objects, role playing, creating
the diagrams, and incorporating useful
patterns.

25

Вам также может понравиться