Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Object Model

The document discusses key concepts in object-oriented programming including objects, classes, associations, aggregation, composition, and inheritance. It defines an object as something that can have state, behavior, and identity. A class is a template that defines the common attributes and behaviors of objects. Classes can be associated or related through aggregation, composition, or inheritance hierarchies to model real-world relationships.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Object Model

The document discusses key concepts in object-oriented programming including objects, classes, associations, aggregation, composition, and inheritance. It defines an object as something that can have state, behavior, and identity. A class is a template that defines the common attributes and behaviors of objects. Classes can be associated or related through aggregation, composition, or inheritance hierarchies to model real-world relationships.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

OBJECTS

INTRODUCTION
 What is an Object?
 How to Describe an Object

 The components of an object

 Finding Objects - Scenario’s

 Object classification
WHAT IS AN OBJECT?
 An object represents either a real world or abstract entity
 Physical:

 Software:

 “Something you can do things to. An object has state,


behaviour, and identity” (Booch, 1994)
 “A Software package that contains a collection of related
data and functions”
OBJECT DATA
 Objects contain data like any other data record.
 Data can be of many different types – characters, strings, integers,
booleans, dates etc.
 1 or several data items will identify the data object;

 Often in object oriented development you will need to identify


objects from scenarios.
 A scenarios is an outline of events which happen at different times
during system execution.
 The nouns in the scenario are a good indicator of the objects

Objects bring TOGETHER:


 systems design, and

 Programming using a single definition in both

 Problem of objects is that they are Very inefficient to produce a


system which has the same operations and variables for each object
CLASSES
THE NEED FOR A CLASS
A ‘class’ is a software
design which describes
the general properties of
Class
something which the
software is modelling.

Individual
‘objects’ are
created from
the class
design for each
Object 1 Object 2 Object 3 Object 4
actual thing
6
CLASSES
 A class is a “template” that defines the methods and
variables to be a particular type of object.
 Objects of a class are called instances

 Class names should be singular nouns

 Class names should come directly from the problem


domain
 If you cannot think of a name then there may be a
problem with the design
REPRESENTING UML CLASSES

Class Name
Attributes

Operations
EXAMPLE UML CLASS

Car
EngineStatus
Gear
Speed

startEngine()
stopEngine() Remember that
changeGear() the class is a
template for creating
objects
CLASS ASSOCIATIONS (I)
 Represent relationships between instance of classes
 Person owns a car

Association has two possible roles


Each a direction on the association
car to person (driven_by) & person to car
(drives)
Class Class

Association
CLASS ASSOCIATION CONTN’D
 Association has two possible roles
 Each a direction on the association
 car to person (driven_by) & person to car (drives)
 A role can be labeled
 You can name the role after the target class
 Symbols used in multiplicity include the following
 1 (exactly one)
 n (where n is a single number)
 * (the range 0 to infinity)
 1 .. * (the range 1 to infinity)
 n1 .. n2 (where n1 and n2 are single numbers forming a range)
 0 .. 1 (zero or one)
MULTIPLICITY EXAMPLE

One Person associates with one car

Car Person
EngineStatus Age
Gear 1 Height
Speed
1 Driver
startEngine() driveCar()
stopEngine()
changeGear()
ASSOCIATION CLASS
 Allows you to add attributes, operations and other features to
associations

Student Module
1..*
studentId moduleId
Attendance 6
NEW CLASS EXAMPLE

Student 1..* Module


studentId moduleId
6

1 1

studentModuleDetails
studentId, moduleId
attendance, marks 1..*
6 register(),marking()
NEW CLASS EXAMPLE

Student Module
studentId moduleId

1 1

studentModuleDetails
moduleId, studentId
attendance, marks 1..*
6 register(),marking()
AGGREGATION & COMPOSITION
COMPOSITE OBJECTS
 Objects which contain other objects are called composite objects.

Fuel Tank

Motorcycle

Engine Wheels
Frame
COMPOSITE OBJECTS

Motorcycle

Frame Wheels Fuel Tank Engine


AGGREGATION
 Aggregation is often referred to as “the part-of
relationship” or the “has a” relationship
 With aggregation the relationship implies that the “whole
is related to its part”
 A Car has an engine and wheels
AGGREGATION CONTN’D
1
Car Engine

Drives

Person
Aggregation
COMPOSITION
 There is a stronger variety of aggregation called
composition
 The part object(s) have no meaning when the
relationship is broken.

 Part object(s) live and die with the whole


 If the COMPONENT OBJECT is detached from its
composite object and can sensibly exist apart from the
Composite Object then the relationship is aggregation,
otherwise it is composition.
COMPOSITION

Diagram illustration

Book Pages

Composition
INHERITANCE
GENERALISATION
 Also known
as Vehicle
inheritance

Car Lorry
INHERITANCE EXAMPLE(1)
 Consider these objects

Red Car Yellow Truck

Blue Car Green Truck


INHERITANCE EXAMPLE(2)
 We can see that there are two car objects and two truck
objects
 There are two classes ...

Car Truck
SUPERCLASSES AND SUBCLASSES
 A class defined in terms of another.

SuperClass

Subclasses
AN INHERITANCE TREE
Vehicle

Car Truck

SportsCar Hatchback Fixed Wheel Articulated


Base

2 axle 3 axle
INHERITANCE TREE

Vehicle
is a vehicle

Truck is a truck

Fixed Wheel is a Fixed WheelBase


Base

3 axle
A 3 axle truck
MULTIPLE INHERITANCE

Manager Salesman

SalaryAddition() SalaryAddition()

Management’s
Bonus Salesperson’s
Sales Manager Commission

You might also like