Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Chapter 5: Object Basics

Learning Objectives
In this chapter you will learn
 Object
 Class
 Basics terms used with objects

1. Object

 An abstraction of something in a problem domain, reflecting the capabilities of


the system to keep information about it, interact with it, or both. (Coad & Yourdon
1990)
 Represents only features of a thing that are deemed relevant to the current
purpose
 Objects are all around us.
 Object has structure. That it has attributes (properties) and behavior

2. Classes

 A class is a set of objects that share a common structure and a common


behaviour
 A single object is an instance of a class
 Example:
Ali, Abu, Alice & Angie are instances/objects of the
Employee Class

3. Attributes: Object State & Property

 Properties represent the state of an object


 Example: Attributes of a car object Car

Cost
Colour
Make
Model

4. Object Behaviour & Methods

 Object behaviour is described in methods or procedures


 A method is a function or procedure that is defined for a class and typically can
access the internal state of an object of the class to perform some operation
 Behaviour is a collection of methods that describes what an object is capable of
doing
 The object (known as the receiver) is that on which the method operates

KM 104 Page 1 of 4
Chapter 5: Object Basics

5. Messages
 Messages are non-specific function calls that can invoke an object to do
something

6. Messages Vs. Methods

 Message tells the object what to do


 Method tells the object how to do something
 Example:
You want the cook to prepare spaghetti for lunch
Message: I want spaghetti for lunch
Method: Steps involved in getting the spaghetti ready for lunch

7. Polymorphism

 Poly means many and morph means forms


 Polymorphism means that the same operation may behave differently on
different classes

8. Encapsulation & Information Hiding

 Information hiding is the principle of concealing an object’s internal data and


procedures and providing an interface to each object in such a way as to reveal
as little as possible about its inner workings
 An object is said to encapsulate the data and a program; this means that the user
cannot see inside the object “capsule”, but can use the object by calling the
object’s methods

9. Data abstraction

 Incorporates encapsulation and polymorphism


 Data are abstracted when they are shielded by a full set of methods and only
those methods can access the data portion of an object

10. Class Hierarchy

 An object-oriented system organises classes into subclass-superclass hierarchy


 Different properties and behaviours are used as the basis for making distinctions
between classes and subclasses
 At the top of the class hierarchy are the most general classes and at the bottom
are the most specific
 A subclass inherits all the properties and methods defined in its superclass
 Subclasses generally add new methods and properties specific to that class
 Subclasses may refine or constrain the state and behaviour inherited from its
superclass
 Superclasses generalise behaviour
 A class may simultaneously be the subclass to some class and a superclass to
another class(es)

KM 104 Page 2 of 4
Chapter 5: Object Basics

 An object-oriented system eliminates duplicated effort by allowing classes to


share and reuse behaviours
 Note: Superclass is also known as base and subclass is also known as derived
 Example: Shown below is a superclass/subclass hierarchy

Motor Vehicle

Bus Truck Car

Ford

Mustang Taurus Thunderbird

11. Inheritance

 It is a property of object-oriented systems that allows objects to be built from


other objects
 It is a relationship between classes where one class is the parent class
(superclass) of another class (subclass)
 Inheritance believes in programming by extension rather than programming by
reinvention
 Inheritance allows classes to share and reuse behaviours and attributes
 Where behaviour of a class instance is defined in that class’ methods, a class
also inherits the behaviours and attributes of all of its superclasses
 Whenever checking on which method to invoke, the check would start from the
bottom of the hierarchy and moving upwards
 If no appropriate method is found, then nothing would be done
 In some instances, similar method types would exist in both subclasses and
superclasses
 As invoking of method is done bottom-up, then the method in the subclass would
be invoked first and the same method in the superclass would not be invoked;
the check process would stop at the level of the subclass

12. Multiple Inheritance

 A subclass can inherit behaviours and attributes from more than one superclass

13. Object and Identity

 A special feature of object-oriented systems is that every object has its own
unique identity
 An object’s identity comes into being when the object is created and continues to
represent that object from then on
 This identity never is confused with another object, even if the original object has
been deleted
 The identity name never changes even if all the properties of the object change –
it is independent of the object’s state

KM 104 Page 3 of 4
Chapter 5: Object Basics

 Object identity is often implemented through some kind of object identifier (OID)
or unique identifier (UID)

14. Reference Materials:

 Object-oriented Systems Development using the Unified Modelling Language (Ali


Bahrami)
Chapter 2: Object Basics

 Systems Analysis & Design (Kendall & Kendall)


Chapter 22: Object-oriented Systems Analysis and Design

 Object-oriented Systems Analysis & Design Using UML (Bernett, McRobb &
Farmer)
Chapter 4: What is Object-orientation?

 SAM Teach Yourself UML in 24 Hour


Chapter 2 : Understand Object-Orientation.

KM 104 Page 4 of 4

You might also like