Procedural Programming
- Procedural Programming is like a recipe
- inputs
- steps (sequence)
- output
Object Oriented Programming
- Object:
- contains
- capabilities
Examples
- Bank Account
BankAccount
contains:
account number
account type
balance
characteristics:
transfer
withdraw
deposit
- Laptop
contains:
configuration
cpu
ram
storgae
os
features
characteristics:
start
shutdown
browser
...
...
- Library
book
shelf
newspaper
transaction
librarian
user
- Object oriented programming has two important concepts
- Class: Here we are building a cookie cutter/ design (Blueprint)
- In programming world we write class to specify structure
- Object: This is what we operate on (cookie/home/ac).
- We create object from class and object has
memory/cpu/resourcesattached to it.
- We create object from class and object has
- Class: Here we are building a cookie cutter/ design (Blueprint)
Writing a class
- Class is a blueprint
- members are contents (variables)
- methods are capabilities (functions)
- Classes or objects can have relationships
- To classify these relationship all we have to figure out is
is-arelationshiphas-arelationship
- Technically in OOD we have 4 types of relationships that can exist
- Association:
uses - Aggregation:
Weak has-a - Composition:
Strong has-a - Inheritence:
is-a
- Association:
Exercise
- Identify classes for Restaurant, we are supposed to build a Billing system
- Restaurant
- Menu
- MenuItem
- Tables
list<Table> - Order
- OrderItem
- Bill
- Payment
- Menu
contents:
menu items
- Menu Item
contents:
id
category
price
name
- Table
content:
number
capacity
- Order
content:
id
list<orderItem>
status
capability:
generate_bill()
cancel
- OrderItem
content:
id
menuitem_id
quanity
- Bill
contents:
id
Order
amount
tax
total
capabilites:
pay()
UML Diagrams
- Refer Here for visual paradigm
Principles
- Abstraction
- Encapsulation
- Polymorphism
- SOLID
- DuckTyping (Python special)
Refer Here for the notebook created in the class
