-Introduction- Basics of Objects
-Introduction- Basics of Objects
Basic concepts of OO
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
2
06-01-2025
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
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
11
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
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
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
wang : Professor
name = “wang”
age = 35
speciality = “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
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
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
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 ?
13
06-01-2025
An Inheritance Hierarchy
Vehicle
31
Superclass
(parent)
Inheritance
Relationship
Savings Checking
Subclasses
Descendents
32
14
06-01-2025
Multiple Inheritance
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
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
37
Shape
Cube
Tube
Canonical
<<Interface>>
(Class/Stereotype) Shape
Representation Pyramid
draw()
move()
scale()
rotate() Cube
38
17
06-01-2025
Circle Rectangle
draw () draw ()
39
Further Reading
40
18