DevOps Classroom notes 15/Oct/2025

Object Oriented Programming Continued

  • Composition refers to has-a relationship
class Engine:
    def __init__(self, manufacturer: str):
        self.manufacturer = manufacturer

    def start(self):
        print("Engine Started")

    def stop(self):
        print("Engine Stopped")

class Car:
    def __init__(self, engine:Engine):
        self.engine: Engine = engine

    def start(self):
        print("Battery started")
        self.engine.start()
        print("AC on...")


engine = Engine("Fiat")
car = Car(engine)
car.start()
  • Refer Here for objects
  • python does not support private or protected as keywords but by conventions we can acheive the same behavior. when every we add __ double underscore as prefix member or method it cannot be accessed from outside
  • Abstract classes in python
  • Refer Here for notebook
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%%