Title: Objectoriented concepts
1Object-oriented concepts UML 1
- LectureConcepts and ApproachesBasis of the
Object-Oriented Paradigm
2An Introduction to Objects
- Basis of the Object-Oriented Paradigm
3What are Objects?
- A thing presented or capable of being presented
to the senses a thing observed .. that upon
which attention, interest or some emotion is
fixed Chambers Dictionary - A tangible and/or visible thing, something that
may be apprehended intellectually, something
towards which thought or action is
directedBooch
4 quite, but What are Objects?
- Examples (of which there are many)PeopleMotor
CarsPersonal Computersetc. etc. etc. etc.
etc. etc. etc. ...
5Objects Possess State
- The state of an object encompasses all of the
(usually static) properties of the object plus
the current (usually dynamic) values of each of
these properties - Think of state as the data possessed by an
object - An object can manipulate (change, copy, delete)
its data
6Objects Display Behaviour
- Behaviour is how an object acts and reacts, in
terms of its state changes and message passing - Think of behaviour as an objects internal
functions - Objects are responsible for instructing their own
functions to operate and for requesting other
objects to instruct their own functions
7Objects Have Identity
- Identity is that property of an object which
distinguishes it from all other objects - Think of identity as being represented by an
objects name - In the O-O model, all objects have completely
unique names
8Objects Communicate
- Objects communicate with one another
- This is achieved by message passing
9Objects Have Relationships
- LinksA physical or conceptual connection
between objectsActors - Operates on other
objects but is never operated
uponServers - Only ever operated
uponAgents - Both operates on and is operated
upon
10Objects Have Relationships
- AggregationDenotes a whole/part hierarchy, for
example
Airplane
Container
Cockpit
Wings
Container/Component
Seats
Engines
Container/Component
11Objects Belong to Classes
- Class and Object are tightly interwoven
- A class is defined as a group, set or kind
marked by common attributes or a common
attribute a group division, distinction or
rating based on quality, degree of competence or
conditionWebsters Dictionary
12 ok, so What is a Class?
- In other words, a class is a set of objects that
share a common structure and a common behaviour - A single object is simply an instance of a class
- Lets look at an exampleMammal describes a class
of animals which possess the attributes and
behaviours associated with being a mammal (eg.
Cows, Monkeys, Humans etc) such as hair, suckle
young, warm-blooded, sexual, smelly etc.
13Class Interfaces and Implementation
- Interfaces allow classes to provide a view of
their internal structure and behaviour to the
outside world - Implementation of a class is its internal view,
ie. what states it possess and which behaviours
it exhibits.
14Class Interface Visibility
- Public Accessible to all clientsProtected acces
sible to itself, subclasses and its
friendsPrivate accessible only to itself
and its friendsIn other words - well formed objects must only allow friends
to access their protected and/or private parts
J
15Class Relationships
- Associations
- Inheritance
- Aggregation
- Utilisation
- Instantiation
16Class Associations
- Denotes a semantic dependency between classes of
objects - Classes possess roles in their relationships
- Class associations have cardinality (one-to-one,
one-to-many, many-to-many, n-m)
17Class Inheritance
- A class can inherit both attributes and behaviour
from one or more superclasses (a parent/child
relationship) - Inherited characteristics can be altered for that
particular class (Polymorphism) - Inheritance is hierarchical
18Class Inheritance
A
D
B
B inherits directly from A
E
C
C inherits directly from B, therefore also
inheriting indirectly from A
E inherits directly from both A and D
19Class Aggregations
- Similar to the aggregation exhibited by objects
- Whole/Part relationship (Container/Component)
- Physical containment and containment by reference
is possible
ShareHolder
ShareHolder is not actually constructed with
Shares but still contains them
Shares
20Class Utilisations
- One class acts as the Server (or Supplier) to
another Client class
Server/Client
Server
Uses
Uses
Client
Uses
21Class Instantiations
- An actual object in the O-O model is instantiated
from a single class - Thus every object is the instance of some class,
and each class can have zero or more object
instances - Hence, classes are static, object instances are
dynamic
22A Class Example - Grand Prix Drivers
Mother
Father
Driving Skill (Inheritance)
Racing Car
Drives (Association)
Contains (Aggregation)
Person
Birth (Instantiation)
Powerful Engine
Pit Stops (Utilisation)
Damen Hill
Pit Crew