06-01-2025
Basic concepts of OO
Basic Concepts of Object Oriented
Object
Class
Message
Basic Principles of Object Orientation
Abstraction
Encapsulation
Inheritance
Polymorphism
Interface and Abstract Class
1
06-01-2025
What Is an Object?
Informally, an object represents an entity, either
physical, conceptual, or software.
Physical entity
Truck
Conceptual entity
Chemical
Process
Software entity
Linked List
A More Formal Definition
Attributes
An object is an entity with
a well-defined boundary
and identity that
encapsulates state and
behavior.
State is represented by
attributes and relationships.
Behavior is represented by
operations or methods, and
Object
state machines.
Operations
2
06-01-2025
An Object Has State
The state of an object is one of the possible
conditions in which an object may exist.
The state of an object normally changes over time.
Name: J Clark
Employee ID: 567138
HireDate: 07/25/1991
Professor Clark Status: Tenured
Discipline: Finance
MaxLoad: 3
Name: J Clark
Employee ID: 567138
Date Hired: July 25, 1991
Status: Tenured
Discipline: Finance Professor Clark
Maximum Course Load: 3 classes
An Object Has Behavior
Behavior determines how an object acts and re-acts.
The visible behavior of an object is modeled by the
set of messages it can respond to (operations the
object can perform).
Professor Clark
Professor Clark’s behavior
Submit Final Grades
Accept Course Offering TakeSabbatical()
Take Sabbatical(leave)
Maximum Course Load: 3 classes Professor Clark
10
3
06-01-2025
An Object Has Identity
Each object has a unique identity, even if the
state is identical to that of another object.
Professor “J Clark” teaches Professor “J Clark” teaches
Biology Zoology
11
Objects Need to Collaborate
Objects are useless and unless they can
collaborate together to solve a problem.
Each object is responsible for its own behavior and
status.
No one object can carry out every responsibility on
its own.
How do objects interact with each other?
They interact through messages.
12
4
06-01-2025
What Is a Class?
A class is a description of a set of objects that share
the same properties and behavior.
An object is an instance of a class.
Class: Professor
Objects
Attributes
Professor Smith
Professor Mellon
Professor Jones
Operations
13
A Sample Class
Class: Automobile
Data Items: Methods:
◦ manufacturer’s name ◦ Define data items
◦ model name (specify manufacturer’s
◦ year made name, model, year, etc.)
◦ color ◦ Change a data item
◦ number of doors (color, engine, etc.)
◦ size of engine ◦ Display data items
◦ etc. ◦ Calculate cost
◦ etc.
14
5
06-01-2025
The Relationship Between Classes and
Objects
A class is an abstract definition of an object.
◦ It defines the structure and behavior of each object in the
class.
◦ It serves as a template for creating objects
Objects are grouped into classes.
An object is an instance of a class.
From Real World Class: Professor
Professor Jones Professor Smith abstracting
Objects
Professor Mellon
instancing
Objects
To computer World
15
What Is an Attribute?
An attribute is a named property of a class that
describes a range of values instances of the
property may hold.
A class may have any number of attributes or no attributes
at all.
Attributes
16
6
06-01-2025
Attributes in Classes and Objects
Class name: M. Modano
address: 123 Main
studentID: 9
dateofBirth: 03/10/1967
Objects
name: D. Hatcher
address: 456 Oak
studentID: 2
dateofBirth: 12/11/1969
17
What Is an Operation?
An operation is the implementation of a service
that can be requested from any object of the
class to affect behavior.
A class may have any number of operations or
none at all.
Operations
18
7
06-01-2025
Practice Questions
Draw UML class diagram for Patient Class with any five
attributes and three operations with visibility markers in
Healthcare Information System.
Draw UML class diagram for Customer Class with any four
attributes and two operations with visibility markers in
Banking Information System.
Draw UML class diagram for Customer Class with any three
attributes and two operations with visibility markers in
Online shopping System.
Draw UML class diagram for Student Class with any six
attributes and three operations with visibility markers in
Students Information System.
19
Example : Instance of Professor
wang : Professor
name = “wang”
age = 35
speciality = “computer”
Professor wang = new Professor (“wang”, 35,
“computer”);
20
8
06-01-2025
What is a message?
A specification of a communication between objects
that conveys information with the expectation that
activity will ensure
One object asks another object to perform an operation.
What is
your name?
Professor wang
wang.getName()
21
Example: Object Interaction
The OrderEntryForm wants Order to calculate
the total dollar value for the order.
calculateOrderTotal()
orderID
date
salesTotal
tax
shipDate
Message
OrderEntryForm Order
The class Order has the responsibility to calculate the total dollar
value.
22
9
06-01-2025
Basic Principles of Object Oriented
Object Orientation
Polymorphism
Encapsulation
Abstraction
Inheritance
23
What Is Abstraction?
Abstraction can be defined as:
Any model that includes the most important, essential,
or distinguishing aspects of something while
suppressing or ignoring less important, immaterial, or
diversionary details. The result of removing
distinctions so as to emphasize commonalties.
(Dictionary of Object Technology, Firesmith, Eykholt,
1995)
Abstraction
Emphasizes relevant characteristics.
Suppresses other characteristics.
BriefCase
- Capacity
- Weight
+ open()
+ close()
24
10
06-01-2025
Example: Abstraction
Student Professor
Course Offering (9:00 AM,
Monday-Wednesday-Friday) Course (e.g. Algebra)
25
What Is Encapsulation?
Encapsulation means to design, produce, and
describe software so that it can be easily used
without knowing the details of how it works.
Also known as information hiding
An analogy:
When you drive a car, you don’t have know the
details of how many cylinders the engine has or how
the gasoline and air are mixed and ignited.
Instead, you only have to know how to use the
controls.
26
11
06-01-2025
What Is Encapsulation?
Hide implementation from clients
clients depend on interface
Improves Resiliency
27
Encapsulation Illustrated
Professor Clark
Professor Clark
needs to be able to
teach four classes in
the next semester.
Name: J Clark
Employee ID: 567138
HireDate: 07/25/1991
Status: Tenured
Discipline: Finance
MaxLoad:4
SetMaxLoad(4)
TakeSabbatical()
28
12
06-01-2025
Encapsulation – Information/Implementation
hiding
Information which can’t be
accessed by client
Balance
Interface insterestYTD
Owner
Client Deposit() Account_number
Withdraw()
Transfer() Deposit() {…}
Withdraw() {…}
Transfer() {…}
Implementation details
which are unvisuable for
client.
29
What Is Inheritance ?
Inheritance —a way of organizing classes
Term comes from inheritance of traits like eye
color, hair color, and so on.
Classes with properties in common can be
grouped so that their common properties are
only defined once.
Inheritance is a kind of relationship
“Is a” relationship
“Part of” relationship
“Kind of" relationship
30
13
06-01-2025
An Inheritance Hierarchy
Vehicle
Automobile Motorcycle Bus
Sedan Sports Car School Bus Luxury Bus
What properties does each vehicle inherit from the
types of vehicles above it in the diagram?
31
Example: Single Inheritance
One class inherits from another.
Ancestor
Superclass
(parent)
Inheritance
Relationship
Savings Checking
Subclasses
Descendents
32
14
06-01-2025
Example: Multiple Inheritance
A class can inherit from several other classes.
Multiple Inheritance
Use multiple inheritance only when needed and
always with caution!
Question: Draw a class hierarchy diagrams for university
systems(Indian or Foreign)
33
Polymorphism
Polymorphism—the same word or phrase can be
mean different things in different contexts
Analogy: in English, bank can mean side of a
river or a place to put money
In Java, two or more classes could each have a
method called output
Each output method would do the right thing
for the class that it was in.
One output might display a number whereas a
different one might display a name.
34
15
06-01-2025
What Is Polymorphism?
The ability to hide many different implementation
behind a single interface.
Manufacturer B
Manufacturer A Manufacturer C
OO Principle:
Encapsulation
35
Example: Polymorphism
Get Current Value
Stock Bond Mutual Fund
36
16
06-01-2025
What is an Interface?
An interface is a collection of operations that specify a service of a
class or component.
Interfaces formalize polymorphism
Interfaces support “plug-and-play” architectures
Tube
<<Interface>>
‘How’
Shape
‘What’ Pyramid
draw()
move()
scale()
rotate() Cube
Realization relationship (stay tuned for realization relationships)
37
How Do You Represent An Interface?
Tube
Elided/Iconic
Representation
(“lollipop”) Pyramid
Shape
Cube
Tube
Canonical
<<Interface>>
(Class/Stereotype) Shape
Representation Pyramid
draw()
move()
scale()
rotate() Cube
(stay tuned for realization relationships)
38
17
06-01-2025
What is an Abstract Class?
An abstract class is a class that may not has any direct
instances.
In the UML, you specify that a class is abstract by writing its
name in italics.
An abstract operation is an operation that it is incomplete
and requires a child to supply an implementation of the
operation.
Shape
Abstract class
{abstract}
draw () {abstract} Abstract operation
Circle Rectangle
draw () draw ()
39
Further Reading
Chapter02 from Ali Bahrami textbook
40
18