Object-
Oriented
Programing
Object-Oriented
Thinking
2
To have ideas, words, or images in your mind, and to use your
Thinking mind to consider something, to form connected ideas, to try
to solve problems, etc. (www.oxfordlearnersdictionaries.com)
3
Objects
Things that have both state and
behavior.
State is the data that an object holds,
such as its name, color, or size.
Behavior is what an object can do, such
as move, change color, or speak.
4
Data of an
Object
The attributes, properties or
characteristics that define the
object
5
Information about the object's
Descriptive Attributes identity, characteristics, or
qualities
6
Quantitativ
e
Attributes
The attributes that can be
measured and assigned as
a number
7
Behavioral
Attributes
These attributes describe the object's
behavior and refer to the actions that an
object can perform.
8
Behavior of an Object
Behavior refers to the actions or The behaviors allow objects to
functions that an object can perform. interact with each other and with the
external world
9
Structural
behavior
The relationships between
the object
• Association
• Aggregation
• Composition
10
Association
a relationship between two objects
that are not part of each other
Tuesday, February 2, 20XX Sample Footer Text 11
Aggregatio
n
Aggregation is a
relationship between an
object and a part of that
object
Tuesday, February 2, 20XX Sample Footer Text 12
Compositio
n
A relationship between an
object and a part of that
object that cannot exist
independently.
Tuesday, February 2, 20XX Sample Footer Text 13
Functional
behavior
The core actions or operations that the
object can perform.
The primary purpose of the object's
existence.
Tuesday, February 2, 20XX Sample Footer Text 14
Object-
Oriented
Analysis
Tuesday, February 2, 20XX Sample Footer Text 15
Key aspects of
object-
oriented
analysis
• Requirements Gathering
• Determining Objects
• Defining Object
Characteristics
• Modeling Relationships
• Creating Use Cases
• Behavioral Modeling
• Creating Diagrams
• Verifying and Validating the
Model
Tuesday, February 2, 20XX Sample Footer Text 16
Requiremen
ts Gathering
•Gathering and understanding the
functional and non-functional
requirements of the system.
•Interactions with stakeholders,
end-users, and domain experts to
capture the system's purpose and
objectives.
Tuesday, February 2, 20XX Sample Footer Text 17
Determinin
g Objects
•The main objects or entities
within the problem domain.
•The real-world entities, concepts,
or components that the system
will manipulate or interact with.
Tuesday, February 2, 20XX Sample Footer Text 18
Look for nouns in the problem statement, requirements, and
Nouns user stories.
Potential objects or entities within the domain.
Tuesday, February 2, 20XX Sample Footer Text 19
Attributes
•What information does the object
need to store in order to be
useful?
Tuesday, February 2, 20XX Sample Footer Text 20
Relationships
•How the nouns are related to each other.
•Relationships between objects represent
connections or interactions in the problem
domain.
Tuesday, February 2, 20XX Sample Footer Text 21
Actions
Think about the actions or
behaviors that these
objects can perform.
Tuesday, February 2, 20XX Sample Footer Text 22
Hierarchies and
Specializations
•If there are different types or categories
of objects, consider creating hierarchies
or specializations.
•This leads to the use of inheritance,
where a base object class can be
extended to create more specific
subclasses.
Tuesday, February 2, 20XX Sample Footer Text 23
Avoid Overloading
Objects
•Not to overload a single object with too
many responsibilities.
•Each object should have a clear and
focused purpose within the domain.
Tuesday, February 2, 20XX Sample Footer Text 24
Model with
Diagrams
Visually represent the
identified objects and their
relationships.
Tuesday, February 2, 20XX Sample Footer Text 25
Iterate and
Refine
Refine your list of objects
based on ongoing
discussions, insights, and
changes in requirements.
Tuesday, February 2, 20XX Sample Footer Text 26
An example of
an online
shopping
system
•The problem is to create an online
shopping system where customers
can browse products, add items to
their cart, place orders, and make
payments.
Tuesday, February 2, 20XX Sample Footer Text 27
Customer
Product
Objects Cart
Order
Payment
Tuesday, February 2, 20XX Sample Footer Text 28
Customer:
Customer ID
Name
Email
Product:
Product ID
Name
Description
Price
Stock Quantity
Attributes Cart:
Cart ID
Name
Order:
Order ID
Order Date
Shipping Address
Order Status
Payment:
Payment ID
Payment Date
Payment Method
Tuesday, February 2, 20XX Sample Footer Text 29
A customer can have a
cart and place an order.
Relationshi An order contains
ps products.
An order involves a
payment.
Tuesday, February 2, 20XX Sample Footer Text 30
Actions
•Customer can browse products,
add to cart.
•Cart can add product, remove
product, view contents.
•Order can calculate total amount,
add product,.
•Payment can process payment.
Tuesday, February 2, 20XX Sample Footer Text 31
Example 2: The
library system The library system is a software
application that manages the
operations of a library. It should
allow librarians to manage books,
members, and lending operations
efficiently. Users should be able to
search for and borrow books, while
librarians should be able to
manage the library's collection,
check-in/check-out books, and
handle fines.
Tuesday, February 2, 20XX Sample Footer Text 32
Book
Member
The main Librarian
objects
Loan
Fine
Tuesday, February 2, 20XX Sample Footer Text 33
Book:
• Title
• Author
• ISBN
• Genre
• Availability status
Member:
• Name
• Member ID
Attributes
• Contact information
Librarian:
• Name
• Staff ID
Loan:
• Loan ID
• Due date
Fine:
• Fine ID
• Amount
• Date assessed
Tuesday, February 2, 20XX Sample Footer Text 34
Book: Check availability
Borrow a book
Member: Return a book
Functional
Add a new book to the
collection
Remove a book from the
Librarian: collection
Behaviors Check out a book to a patron
Check in a book from a patron
Calculate fines
Record loan details
Loan: Calculate due date
Record fine details
Fine: Calculate fine amount
Tuesday, February 2, 20XX Sample Footer Text 35
Structural Behaviors
Association • Members associate with Loans (a Member borrows Books
through a Loan).
: • Librarians associate with Loans (a Librarian manages Loans).
Aggregatio • Books are aggregated into the library's collection.
n:
Compositio • Loans are composed of Books and Patrons (a Loan is a
n:
composition of a Book and a Patron).
Tuesday, February 2, 20XX Sample Footer Text 36
Example 3: The Shipping
Management system • The system should track and manage the
shipment of products from one location to
another.
•It should allow users to create, update, and
delete shipments.
•Users should be able to track the status of
shipments.
•The system should calculate shipping costs
based on various factors such as weight,
distance, and shipping method.
•Users should receive notifications and alerts for
critical shipment events.
•There should be user roles with different levels of
access, such as admin, manager, and customer.
Tuesday, February 2, 20XX Sample Footer Text 37
Shipment
Customer
Carrier
Objects Product
Shipping Address
User
Notification
Tuesday, February 2, 20XX Sample Footer Text 38
Shipping
Shipment: Customer: Carrier: Product: User: Notification:
Address:
• ID • ID • ID • ID • ID • ID • ID
• Status (e.g., • Name • Name • Name • Street • Username • Message
pending, in • Contact • Contact • Description address • Password • Timestamp
transit, information information • Weight • City • Role (admin, • Recipient
delivered) • State manager,
• Shipping • Zip code customer)
method
• Estimated
delivery date
• Weight
• Shipping cost
• Source
address
• Destination
address
• Carrier
information
Attributes
Tuesday, February 2, 20XX Sample Footer Text 39
Create shipment
Shipment: Update shipment status
Calculate shipping cost
Place an order
Customer: Track shipments
Accept and fulfill shipments
Carrier: Provide tracking information
Functional
Product: Add/update product information
Behaviors
Shipping Address: Add/update address information
Login/logout
User: Manage user roles and permissions
Notification: Send notifications to users
Tuesday, February 2, 20XX Sample Footer Text 40
Shipment-Customer Association: A
customer can have multiple shipments,
but each shipment is associated with
one customer.
Shipment-Carrier Association: A
shipment is associated with one carrier,
but a carrier can handle multiple
Structural shipments.
Notification-User Association:
Notifications are sent to specific users.
Behaviors
Shipment-Shipping Address
Aggregation: A shipment has a source
and destination address, which are part
of the shipment.
Shipment-Product Composition: A
shipment can consist of multiple
products.
Tuesday, February 2, 20XX Sample Footer Text 41
Object-
oriented
design
A software engineering approach
that focuses on designing software
systems using the fundamental
concepts of object-oriented
programming
Tuesday, February 2, 20XX Sample Footer Text 42
•Blueprints or templates for creating objects.
Class •The structure and behavior of objects.
•Attributes (Data Members)
• The variables that store data specific to the
class.
• Define the properties or characteristics of
objects created from the class.
• Also referred to as fields or properties.
•Methods (Member Functions):
• Functions defined within a class
• Operate on the class's attributes and
perform specific behaviors.
• Represent the actions that objects of the
Tuesday, February 2, 20XX Sample Footer Text
class can take. 43
Class vs
Objectof classes
Objects are instances
Class for "Person"
Attributes
Name
Age
Gender
Address
Behaviors
GetDetails()
UpdateAddress()
Object for "Person":
Object 1 – Mehmet:
Name: Mehmet BEY
Age: 30
Gender: Male
Address: Mersin University, Çiflikköy
Campus
Object 2 - Fatma:
Name: Fatma HANIM
Age: 25
Gender: Female
Address: Mersin University, Yenişehir
Campus
Tuesday, February 2, 20XX Sample Footer Text 44
Encapsulati
on
The practice of bundling the data
(attributes or properties) and the
methods (functions or behaviors)
that operate on that data into a
single unit called a class
•Data Hiding
•Access Control
•Getters and Setters
•Data Validation
Tuesday, February 2, 20XX Sample Footer Text 45
Person
-name
-age
-grade
Example -gender
-adress
+GetDetails()
+UpdateAddress()
+SetGrade()
Tuesday, February 2, 20XX Sample Footer Text 46
Abstraction
The process of simplifying complex
systems
•Hiding Complexity
•Modeling Real-World Entities
•Data Abstraction
•Behavioral Abstraction
•Hierarchical Abstraction
• Generalization
• Specialization
Tuesday, February 2, 20XX Sample Footer Text 47
top-down
approach / lower-
level abstractions
• Vehicles cars,
motorcycles, bicycles
Examples
bottom-up
approach / higher-
level abstraction
• Cars, motorcycles,
bicycles Vehicles
Tuesday, February 2, 20XX Sample Footer Text 48
Generalizatio
n
The process of defining a general
or higher-level class (a superclass
or base class)
Tuesday, February 2, 20XX Sample Footer Text 49
Example
SavingAccount
account_number BankAccount
balance
account_number
interest_rate
deposit() balance
withdraw() deposit()
get_balance()
add_interest()
withdraw()
get_balance()
CheckingAccount SavingAccount - is a
account_number BankAccount
interest_rate
balance
add_interest()
overdraft_limit
deposit() CheckingAccount - is a
BankAccount
withdraw() overdraft_limit
get_balance() withdraw()
Tuesday, February 2, 20XX Sample Footer Text 50
Specializatio
n
Creating specialized or
derived classes
(subclasses) from a more
general class (superclass)
Tuesday, February 2, 20XX Sample Footer Text 51
Example
BankAccount
Account
account_number
account_number
balance
balance
deposit()
interest_rate
withdraw()
overdraft_limit get_balance()
deposit() SavingAccount - is a
BankAccount
withdraw() interest_rate
get_balance() add_interest()
add_interest() CheckingAccount - is a
BankAccount
overdraft_limit
Tuesday, February 2, 20XX Sample Footer Text
withdraw() 52
Tuesday, February 2, 20XX Sample Footer Text 53
Creating a class
Initializing an object
Classes Instance attributes
and Class attributes
Objects in
Python
Instance methods
Class methods
Static methods
Tuesday, February 2, 20XX Sample Footer Text 54
Single Inheritance
Multiple Inheritance
Multilevel
Inheritance Inheritance
Hierarchical
Inheritance
Hybrid Inheritance
Method Overriding
Tuesday, February 2, 20XX Sample Footer Text 55
Encapsulation
The
Getters
Access signature Overloadin
and
modifiers of a g
setters
method
Tuesday, February 2, 20XX Sample Footer Text 56
Abstract Class
Abstraction Abstract Method
and
polymorphis
Interface
m
Polymorphism
Tuesday, February 2, 20XX Sample Footer Text 57
Association
How to
Aggregation
code
relationshi Composition
ps in OOP Associations
with
Tuesday, February 2, 20XX Sample Footer Text
attributes 58
One-to-One
(1:1)
One-to-Many
(1:N)
Multiplicity Many-to-One
(N:1)
Many-to-Many
(N:N)
Tuesday, February 2, 20XX Sample Footer Text 59
Coupling
Cohesion
Tuesday, February 2, 20XX Sample Footer Text 60
SOLID
Tuesday, February 2, 20XX Sample Footer Text 61