Object Classes In UML. Object Concepts What is an object? How do objects communicate? How is an...

Preview:

Citation preview

Object Classes

In UML

Object Concepts

• What is an object?

• How do objects communicate?

• How is an object’s interface defined?

• What have objects to do with components?

Object• Thing

– Which of the following are objects: hammer, sphere, chemical process, fog, river, anger, cat, grayness, gray cat?

• State– Encapsulated in the data in its attributes

• Behaviour– Understands and reacts to certain messages - can

receive messages and act on them.

• Identity– Can be a name, but shouldn’t be dependent on the

values of its attributes.

Example myClock• Understands the messages

reportTime

resetTimeTo(07:43),

resetTimeTo(12:30)

I.e. resetTimeTo (newTime)

for any suitable value of newTime.

– The object’s interface says it accepts messages of the form reportTime() and resetTimeto(newTime:Time)where Time is a type whose elements are the sensible values of time.

Messages

• A message contains a keyword called a selector - e.g. ResetTimeTo or ReportTime

• A message can have zero or more arguments, as specified by the definition of the message in the interface.

Interfaces

• The object’s public interface defines which messages it will accept regardless of where they come from.

• An object can send itself a message.• The private interface is usable by itself and other

privileged parts of the system - this specifies the attributes of the objects - not viewable to the public. E.g. a clock will have an attribute Time.

Classes

• A class of objects is a group of objects that have the same attribute types and behavior

• Rather than specifying each object, a class definition shows how the object is defined and behaves.

• A Clock class could contain an object myClock. The Clock class has an operation resetTimeTo(newTime:Time); i.e. all of the clocks can reset time.

• myClock is an instance of the Clock class.

Interfaces

• The object’s public interface defines which messages it will accept regardless of where they come from.– A public interface is a method that can be operated on the

class.

• An object can send itself a message.• The private interface is usable by itself and other

privileged parts of the system - this specifies the attributes of the objects - not viewable to the public. E.g. a clock will have an attribute Time.– A private interface is an attribute that is held about the class.

What is a class?

• A business class is a group of objects that have similar attributes and operations.

• Objects are nouns.

• Only objects that need to have data about them recorded are suitable candidates.

• A user may be a business object, but probably is not.

Starting a class diagram

• Choose your candidate objects from the system description.

• For each candidate:– Is there more than one object in this class?– Is this object a system user / location?– Can you describe the type of information you

need to know about each member of this group of objects?

What is an attribute?

• An attribute is the type of information you need to know about each object in a class.

• An attribute is an attribute when:-– it has a finite length– it has a single value for each object

• An attribute is not an attribute when:-– it in turn has several attributes– it has multiple values

What is an association?

• An association is a relationship between object classes.

• An association is used to implement a link between objects – to send messages or instructions from one class to another.– An object from one class can invoke a method

on an object from another class, thereby accessing it through its public interface.

Operations

• What sort of operations are there in a class?– Constructor operations create new objects in

the class.– Selector operations get information about and

from an object in a class.– Mutator operations set information about and

to an object in a class.– Destructor operations destroy objects of the

class.

Starting class diagrams

• Rather than trying to define the entire class– concentrate on the data that is required for

business classes– set up a data model, that can be converted into a

relational database– later, loosen the structure, to give object-

oriented advantages– add operations on the data.

Object oriented modelling and design

• Introduction• The world as seen by the object

• object instances and classes

• object identifiers

• Super and sub classes

• Interaction between classes

three models

• Object model• Static structure of objects in a system and their

relationships• Contains class diagrams

• functional model• data value transformations within a system - Use case

and object interaction diagrams

• dynamic model• describes aspects that change over time: state transition

diagrams

function

datatime

Object modelling

• Object - Class (v instance)• Attributes (v values)• Abstraction and encapsulation

– Abstraction is when a client of a module doesn’t need to know more than is in the interface.

– Encapsulation is when a client of a module isn’t able to know more than is in the interface.

• Method - implementation of an operation for class• Method signature - number and types of arguments; type

of result value• Notation of object instances and classes

Sample object classes«business»::Person

age

name

social security number

«business»::Elevator

Capacity

Highest floor

Location

Lowest floor

Model type

Speed

Go down

Go up

stop

«business»::Telephone call

Hang up time

Number

Start time

date

Hang up

Play message

Sound dial tone

dial

find connection

get cost

play fast busy tone

ring bell

slow busy tone

sound loud beep

valid number

«business»::Caller

1..* 1makes

These are examples of objectclasses; some have operationsassociated with them. All haveattributes associated with them.

Adding relationships

• Links• Physical or conceptual connection between object

instances

• Associations• Groups of links with common structure and common

semantics

• bi-directional; forward and inverse

• direction implied by the name is forward

Link Notation

• class associations

• one to one

• zero or many

• one to many

• many to many

*

1..*

1

1

1

1..* 1..*

Sample associations«business»::Country

name

«business»::City

name

«business»::Workstation

«business»::Window

Close

Display

Hide

Open

11

has capital

10..1

console

Examples

• Identify some of the classes that you would expect to find in each of the following systems:– A system for a library– A system to manage hotel bookings– A mail-order clothes system– An airline booking system– A system for an X-ray clinic

Class Person

• List the attributes that a person would have in each of the following systems:– A system for a library– A payroll system– A voting registration system– A sporting club registration system– A dentist’s system

Recommended