Python Classroom notes 29/Apr/2025

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/resources attached to it.

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-a relationship
    • has-a relationship
  • 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

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

Principles

  • Abstraction
  • Encapsulation
  • Polymorphism
  • SOLID
  • DuckTyping (Python special)

Refer Here for the notebook created in the class

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%