+ All Categories
Home > Documents > OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.

OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.

Date post: 28-Dec-2015
Category:
Upload: elinor-bishop
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
24
Transcript

OBJECT AND CLASES: THE BASIC CONCEPTS

Pertemuan 8

Matakuliah : Konsep object-oriented Tahun : 2009

A Student Guide to Object- Orientated Systems

Chapter 4 Objects and Chapter 4 Objects and Classes: the basic Classes: the basic conceptsconcepts

33

Objects and Classes – the basic concepts

• Use cases model the user’s view of the functionality of a system. Each use case represents a task or major chunk of functionality

• Object orientated software structure based on objects

• Objects must deliver all the system functionality

44

What is an object?The most important concept in object-orientated

development• A representation of something in the application

domain about which we need to store data to enable the system to provide the required functionality.

55

What is an object?

66

aBike :Bike

type = men’sdailyHireRate = £8deposit = £50

Object name – two optional parts, both underlined

aBike = this specific object’s name

Bike = the class the object belongs to

The object’s attribute values

Attributes are data items defined as part of an object or class.

• type is an attribute• men’s is the value of the ‘type’ attribute for this object

2 sections, top is the object’s name, bottom is the object’s attribute values

More about objects

• Every object belongs to a class

• Objects in an O-O system can represent

– physical things (customers, products, members, and books),

– conceptual things (orders, loans, reservations and cancellations)

– organizational things (companies or departments).

– computer implementation features (GUI windows, files or linked lists)

77

More about objects

• Every object in a system has three characteristics

– Behaviour, real world objects have certain attributes and behaviour

– State, object behaviour may vary depending on its state

– Identity, each object has a unique identity and existence

88

Object characteristics – behaviour

Real world objects• Car has data and characteristic behaviour.

Data – amount of fuel, engine temperature, speed. Behaviour – stop, start, move.

Object orientated objects• In OO data becomes attributes• Behaviour becomes operations (procedures)• Data and behaviour are packaged together

99

Object characteristics – state

An object’s state is determined by the value of its attributes

e.g. Bank a/c with no overdraft allowedAttribute determining state = balance

1010

Value of balance attribute = £100Behaviour – Withdrawal of £90 allowedWithdrawal of £150 denied

Value of balance attribute = £300Behaviour – Withdrawal of £90 allowedWithdrawal of £150 allowed

Object characteristics – identity

• Every object has an identity• Every object is a unique• Each object has a separate existence and

ultimately a separate space in memory • Objects whose attribute values are identical

are totally distinct from one another.

1111

Encapsulation

• Encapsulation - packaging related data and operations together

• Data hiding – making the internal details of an object inaccessible to another object

• Public interface – provides the services an object makes available to other objects.

1212

Encapsulation

1313

dataOperations

Data inside an object is surrounded by a protective ring of operationsThe data is protected by the operations that encapsulate it.

Public interface – an object’s name, class and operations, the only parts of the object accessible to other objects.

Class

• An object is defined in terms of its class

• A class of objects is a group of objects with the same set of attributes, relationships and behaviour

• An object is an instance of a class

• Instantiation is creating a new object

1414

Class

1515

Bikebike#availabletypesizemakemodeldailyHireRatedeposit

getCharges (no.days)findBike (bike#)

registerBike (bikeDetails)

getBike# ()

Class name – starts with capital letter, if two words ‘CarPark’

Attributes – lower case, no spaces, each subsequent word starts with capital letter

Operations – same notation as attributes

Relationships

Three types of relationships

»Association

»Aggregation

»Inheritance

• These are links between classes that are used for message passing

• A navigable path between objects1616

Association – a link between two classes indicating a

relationship

1717

0..*

Student

1..*

Course

0..* 1..*

studies

Association relationship between Student and Course classes

• The association can be named: a student studies a course. • An association has two ends each attached to a class.• The numbers and asterisk on the line indicate the multiplicity of the association.

Multiplicity – UML notation

1818

Meaning Example Notation

an exact number

exactly one exactly six

1 (or may be omitted)6

many zero or more one or more

0..* 1..*

a specific range

one to four, zero to six

1..4, 0..6,

a choice two or four or five 2, 4, 5

unspecified an arbitrary, unspecified number

*

Aggregation – a whole-part relationship

Wheel Door Engine

Car

14 2,4,5 1

1919

Identified by - 'consists of', 'has a', or 'is a part of‘Wheels, doors and engine are ‘part’ of a car

Composition – tighter aggregation

• the whole object has exclusive ownership of its parts i.e. the part object can only participate in one aggregation;

• the parts live and die with the whole

Head

Hand

Wheel

WierdoRobot

3

2

66

3

2

2020

Inheritance and generalization

2121

Inheritance – mechanism for defining a new class in terms of an existing class

Generalization – moving common attributes and operations in to a more general class

VisitorsCard

cardNumbercurrentDate

delete ()

StaffCard

cardNumbernamedeptexpiryDate

delete ()

Inheritance and generalization

2222

VisitorsCard currentDate

delete( )

StaffCard name dept. expiryDate

delete( )

Card cardNumber

delete( )

• a specialized class inherits from a general class• a subclass inherits from a superclass• a child class inherits from a parent class• a derived class inherits from a base class.

Relationship described as‘is-a’‘is–a-type-of’‘is–a–kind–of’

Abstract class – never instantiated

2323

Card{abstract}

cardNumber

delete()

Inheritance a relationship between classes

Card objects will never be created (instantiated)

Polymorphism

• The term polymorphism means the ability for a single message to produce a different response depending on the class of the object to which it is sent.

• Polymorphism linked with an inheritance hierarchy allows a single message to be interpreted differently by different objects.

• Which method is executed will depend on which object receives the message.

• A single operation may be implemented by more than one method. 2424


Recommended