Search . . .
Object Oriented
Programming
Session-13
simrantechmentor
What is OOP? Search . . .
Object Oriented Programming is a software development methodology that
design and manage software around objects.
Goal of Object orientation programming is to implement real world working
into Program. In other words, we can say it is based on Realistic modelling.
simrantechmentor
Search . . .
Important Terminology in OOP
Class
Object
Attribute
Behavior
simrantechmentor
Search . . .
What is Object ?
Object represent real life entities. (Any thing that exist)
Attribute
Behavior
simrantechmentor
Search . . .
Attribute
Attribute represent quality, property or state of the object.
Variable → Attribute
name
course
fees
Student Object contactno
simrantechmentor
Search . . .
Attribute
Model Name
Model No
Mileage
Price
Honda Car
Color
simrantechmentor
Behavior Search . . .
Behavior represent action or task that objects perform
Behavior → Methods (Function)
Behavior use attributes (knowledge) to perform task.
attendClass
SubmitFees
takeExam
Student Behavior applyCertificate
simrantechmentor
Search . . .
Behavior
browseCar
buyCar
sellCar
Honda Car
Service Car
simrantechmentor
Search . . .
What is Class ?
Class is a group of objects that share common characteristics.
Class is a template or blueprint that defines attributes and behavior that is common to all
objects.
It provides reusability.
simrantechmentor
Example Search . . .
STUDENT Student
ROLLNO
NAME
DOB
GENDER
COURSE
FEES
CONTACTNO
takeAdmission
attendClass
takeExam
applyCertificate
Raman, Java, 5000 Vinay, Python, 8000
simrantechmentor
Example Search . . .
CAR Car
ModelNo
ModelName
Mileage
Price
NoofWheels
AirBag
MusicSystem
buyCar
sellCar
serviceCar
Honda City, Tata ABC, Maruti XYZ
13 14 12
simrantechmentor
Search . . .
Objects in School (Example)
Class & Objects in School (Example) Search . . .
STUDENT TEACHER
OFFICE STAFF
Search . . .
Objects in STORE (Example)
Search . . .
Class & Objects in STORE (Example)
PRODUCT CUSTOMER EMPLOYEE
Search . . .
Class Example ( STORE)
PRODUCT CUSTOMER
PRODUCTID CUSTOMERID
PRODUCTNAME CUSTOMERNAME
PRICE ADDRESS
DESCRIPTION CONTACTNO
IMAGE IMAGE
AVAILABLE CITY
ORDER
addProduct() ORDERID registerCustomer()
updatePrice() PRODUCTID updateDetails()
deleteProduct() CUSTOMERID deleteAccount()
updateAvailablity() SHIPPINGADRESS
addToCart() ORDERDATE
ORDERSTATUS
placeOrder()
Cancelorder()
trackOrder()
Object Example ( STORE)
Search . . .
PRODUCT
PRODUCTID
PRODUCTNAME
PRICE
DESCRIPTION
IMAGE
AVAILABLE
addProduct()
updatePrice()
deleteProduct()
updateAvailablity()
addToCart()
Object 1
Object 2
Product ID= P001
ProductName=“Arrow T-Shirt” Product ID= P002
Price=1500 Available=“No”
Description=“XYZ”
Image=“abc.jpg”
Available=“Yes”
addProduct() updateAvailablity()
Search . . .
Class Example (Online HOTEL BOOKING)
ROOM CUSTOMER Booking Payment
ROOMNO CUSTOMERID BookingID BillID
ROOMTYPE CUSTOMERNAME RoomID CustomerID
PRICE ADDRESS CUSTOMERID BillingDate
DESCRIPTION CONTACTNO CheckInDate BillAmount
Available CITY CheckOutDate PaymentMode
PaymentStatus
addRoom() addDetail() Reservation() makePayment()
showroom() updateDetail() cancelReservation() processRefund()
updateAvailablity() deleteDetail()
bookRoom()
Search . . .
Object Example (Online HOTEL BOOKING)
Booking-1
BookingID=“B001”
Booking RoomID = 2
CUSTOMERID= C001
BookingID
CheckInDate = 12/01/2023
RoomID
CheckOutDate =13/01/2023
CUSTOMERID
CheckInDate Reservation()
CheckOutDate
Booking-2
Reservation() BookingID=“B002”
cancelReservation() RoomID = [4,5,7]
CUSTOMERID= C003
CheckInDate = 11/01/2023
CheckOutDate =15/01/2023
Reservation()
Demonstration Class & Object Search . . .
Program class_example_1.py (Folder In-class Demo) Lab 13
Demonstration Class & Object Search . . .
Program class_example_2.py (Folder In-class Demo) Lab 13
Demonstration Class & Object Search . . .
Program class_example_3.py (Folder In-class Demo) Lab 13
Search . . .
Special Methods
__init__()
__str__()
simrantechmentor
Search . . .
Special Methods __init__()
__init__() method is a special method also known as constructor it called
automatically as soon as object of the class created.
We use __init__() method to initialize the attributes of an object.
simrantechmentor
Demonstration __init__() method Search . . .
Program class_example_4.py (Folder In-class Demo) Lab 13
Demonstration __init()__ Search . . .
Program class_example_5.py (Folder In-class Demo) Lab 13
Special Methods __str__() Search . . .
returns the string representation of object.
Program class_example_6.py (Folder In-class Demo) Lab 13
simrantechmentor
Inheritance Search . . .
Permanent Employee PartTime Employee
EmployeeId EmployeeId
Name Name
Address Address
Experience Experience
Contactno Contactno
Salary Salary
Provident_fund_no contract_expire_year
addEmployee() addEmployee()
viewEmployee() viewEmployee()
calculateSalary() calculateSalary()
applyBonus() Contract_validation()
availMedicalInsurance()
simrantechmentor
Inheritance Search . . .
Employee
EmployeeId
Name
Address
Experience
Contactno
Salary
addEmployee()
viewEmployee()
calculateSalary()
Permanent Employee PartTime Employee
Provident_fund_no contract_expire_year
applyBonus() Contract_validation()
availMedicalInsurance()
simrantechmentor
What is Inheritance? Search . . .
Inheritance allows us to define a class then inherits all the attributes and
method of existing class and adding its own attributes and methods.
Generalization is keeping attributes and methods that are common to two or
more classes in one class in order to reduce coding effort and save time.
Specialization refers to adding its own attributes and methods other than the
inherited method and attributes.
simrantechmentor
What is Inheritance? Search . . .
Class that has attributes and methods that will be shared by other classes.
Parent Class Base Class Super Class Generalized
Class that inherit method and attributes from existing class.
Child Class Derived Class Sub Class Specialized
simrantechmentor
Demonstration Inheritance Search . . .
Program class_example_7.py (Folder In-class Demo) Lab 13
Polymorphism Search . . .
One object many form.
In inheritance polymorphism can be done by overriding a function by child
class that has same name in parent class.
simrantechmentor
Demonstration Inheritance Search . . .
Program class_example_8.py (Folder In-class Demo) Lab 13
Abstraction & Encapsulation Search . . .
Abstraction is a feature that shows the relevant information.
Encapsulation wraps data and code for necessary information.
simrantechmentor
Search . . .
THANK YOU
Kindly perform all in class exercise before coming to lab
END SLIDE
simrantechmentor
Contact No : 9878138788
Email : [email protected]