ICS 2201 Lecture 1 Overview of OO Paradigm
ICS 2201 Lecture 1 Overview of OO Paradigm
Programming
Lecture 1:Review of OO Programming
Principles
sequencing of steps
Programs = Algorithm + Data Structure
An algorithm is a set of A data structure is a construct
instructions for solving a used to organize data in a specific
problem way.
Most computer languages, from early examples like FORTRAN and ALGOL to more
recent languages like C and Ada, have been imperative or procedural.
Procedural Programming - Example
Writing a program to handle bank accounts
Customer can open different type of accounts, such as
cash account, check account and Loan account.
For each account, customer can deposit, withdraw or
transfer.
How is it implemented in HLL such as C or Java?
As a set of procedures/modules acting on a piece of data
Procedural Programming - Example
Programs = Algorithm + Data Structure
Struct account {
char name; Procedure 1: Deposit() {...}
Data Structure: int accountId;
float balance; Procedure 1: Withdraw() {...}
Bank Account
float interestYTD;
char accountType; Procedure 1: Transfer() {...}
};
BankAccount
balance : float
interestYTD : float
owner : char
account_number : int
Physical entity
Truck
Conceptual entity
Chemical
Software entity Process
Linked List
Example
Real-world objects have attributes and behaviors.
Examples:
Dog
Attributes: breed, color, hungry, tired, etc.
Behaviors: eating, sleeping, etc.
Bank Account
Attributes: account number, owner, balance
Behaviors: withdraw, deposit
Software Objects
Writing software often involves creating a
computational model of real-world objects and
processes.
a well-defined boundary
and identity that
encapsulates state and
behavior.
State is represented by
attributes and relationships.
Behavior is represented by
operations, methods, and
state machines.
Object
Operations
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
Ac
ce
ptC
s ()
ou
de
r
ra
se
alG
Of
fer
in
itF
ing
bm
( )
Su
Professor Clark
Se
tM
Professor Clark’s behavior ax
Lo
a d(
)
Submit Final Grades
TakeSabbatical()
Accept Course Offering
Take Sabbatical Professor Clark
Maximum Course Load: 3 classes
An Object Has Identity
Each object has a unique identity, even if the state
is identical to that of another object.
Objects Professor
Attributes - name
- employeeID : UniqueId
Professor Smith - hireDate
- status
- discipline
- maxLoad
Professor Mellon
+ submitFinalGrade()
Professor Jones + acceptCourseOffering()
+ setMaxLoad()
Operations + takeSabbatical()
Classes
The definitions of the attributes and methods of an object are
organized into a class. Thus, a class is the generic definition
for a set of similar objects (i.e. Person as a generic definition
for say Jane, Paul and Susan)
number: 036
balance: $941
Encapsulation
When classes are defined, programmers can specify that
certain methods or state variables remain hidden inside the
class.
These variables and methods are Visible Methods
accessible from within the class, but not
Hidden
accessible outside it. State
The combination of collecting all the Variables
and
attributes of an object into a single class Methods
definition, combined with the ability to hide
some definitions and type information Visible Variables
within the class, is known as
encapsulation.
Class
Definition
Graphical Model of an Object
Instance balance()
variables
Methods
accountNumber()
Account
class
variable count: 3 num: 036
num: 054 num: 712
bal: $19 bal: $240 bal: $941
printCount()
Class
method
A Sample Class
Class: Automobile
Data Items: Methods:
manufacturer’s name Define data items
model name (specify
manufacturer’s name,
year made
model, year, etc.)
color Change a data item
number of doors (color, engine, etc.)
size of engine Display data items
etc. Calculate cost
etc.
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.
Class: Professor
From Real World
Professor
Professor Jones Professor Smith abstracting
Objects
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
Professor Mellon - maxLoad
instancing + submitFinalGrade()
J Clark : Objects + acceptCourseOffering()
+ setMaxLoad()
Professor + takeSabbatical()
To computer World
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.
Student
- name
- address
Attributes
- studentID
- dateOfBirth
Attributes in Classes and Objects
Student Objects
- name
- address
- studentID
- dateOfBirth
name: D. Hatcher
address: 456 Oak
studentID: 2
dateofBirth: 12/11/1969
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.
Student
+ get tuition()
+ add schedule()
Operations + get schedule()
+ delete schedule()
+ has pre-requisites()
Example: class Professor
class Professor {
private String name;
private int age; Professor
private String speciality;
- name : String
- age : int
public Professor (String sm, int ia, String ss) {
- speciality : String
name = sm;
age = ia;
+getName() : String
speciality = sst; +getAge() : int
} +getSpeciality() : String
public String getName () { return name;}
public int getAge () { return age;}
public String getSpeciality () {
return speciality;}
}
Example : Instance of Professor
wang : Professor
name = “wang”
age = 35
speciality = “computer”
Professor wang
wang.getName()
Example: Object Interaction
The OrderEntryForm wants Order to calculate the
total dollar value for the order.
()
ta l
rTo
e
calculateOrderTotal()
rd
te O
la
lcu
orderID
Ca
date
salesTotal
tax
shipDate
Message
OrderEntryForm Order
The class Order has the responsibility to calculate the total dollar value.
Basic Principles of Object Orientation
Object Orientation
Polymorphism
Encapsulation
Inheritance
Abstraction
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()
Example: Abstraction
Student Professor
An analogy:
When you drive a car, you don’t have know the
controls.
What Is Encapsulation?
Hide implementation from clients
clients depend on interface
Improves Resiliency
Encapsulation Illustrated
Professor Clark
Professor Clark
needs to be able to Ac
ce
teach four classes ptC
s ()
de
ou
ra
rs e
in the next
lG
Of
ina
fer
itF
ing
semester.
Name: J Clark
bm
Su
Employee ID: 567138 ()
HireDate: 07/25/1991
Status: Tenured
Se
SetMaxLoad(4) tM Discipline: Finance
ax MaxLoad:4
Lo
ad
( )
TakeSabbatical()
Encapsulation – Information/Implementation hiding
Inheritance
Relationship
Savings Checking
Subclasses
Descendents
Example: Multiple Inheritance
A class can inherit from several other classes.
FlyingThing Animal
Multiple Inheritance
Manufacturer B
Manufacturer A Manufacturer C
OO Principle:
Encapsulation
Example: Polymorphism
Get Current Value
get get
Cu Cu get
rr e rr e Cu
ntV ntV rr e
alu alu ntV
e( ) e( ) alu
e( )
‘What’ Pyramid
draw()
move()
scale()
rotate() Cube
Shape
Cube
Tube
Canonical
<<Interface>>
(Class/Stereotype) Shape
Representation Pyramid
draw()
move()
scale()
rotate() Cube
Shape
Abstract class
{abstract}
draw () {abstract} Abstract operation
Circle Rectangle
Inheritance
The advantage of making a new class a subclass is
that it will
inherit attributes and methods of its parent class
(also called
the superclass).
class SavingsAccount
class Account { extends Account {
method acctNum() {…} method rate() {…}
method balance() {…} }
method deposit() {…}
method withdraw() {…}
} class CheckingAccount
extends Account {
method withdraw() {…}
}
New Account Types - Cont’d
Account SavingsAccount CheckingAccount
rate() withdraw()
Manager Employee
Message
To: Employee
Method: getHired
Parameters: salary = $45,000, start_date = 10/21/99
Benefits of Messages
Message passing supports all possible interactions between
two objects.
Sequential
Waterfall method, Structured Analysis & Design
Iterative, Spiral and Recursive Methods
There are a huge variety of these
“Agile” or “LightWeight” Software Methods fit into this class
Parallel Effort
Unmanaged, Chaotic
Analysis and Design Space
Analysis and Design Space - Cont’d
Outline
Key Object-Oriented Systems Concepts
Basic Software Lifecycle Concepts
Introduction to OOA/OOD
Scenarios and Use Cases
CRC’s
Sequence Diagrams
Class Diagrams
UML Models
Use Cases
Use cases describe the basic business logic of an application.
Use cases typically written in structured English or Diagrams
Represent potential business situations of an application
Describes a way in which a real-world actor – a person,
organization, or external system – interacts with the
application.
Responsibilities:
Sequence Diagrams
84
Review: Introduction to Object
Orientation
State 2 differences between functional
programming and OOP.
What are the four basic principles of object
orientation? Provide a brief description of
each.
What is an Object and what is a Class?
What is the difference between them?
What is an Attribute?
What is an Operation?
Describe the strengths of object orientation.
85