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
