Created
October 7, 2018 16:41
-
-
Save ZoranPandovski/38f73e4102881095ff4f3fb18170e12f to your computer and use it in GitHub Desktop.
Abstract Factory in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
def drive(self): | |
print("Starting the Car engine!") | |
class Bus: | |
def drive(self): | |
print("Starting the Bus engine!") | |
class CarFactory: | |
def get_vehicle(self): | |
''' Return Car object''' | |
return Car() | |
class VehicleStore: | |
''' VehicleStore houses Abstract Factory''' | |
def __init__(self, vehicle_factory=None): | |
self._vehicle_factory = vehicle_factory | |
def buy_vehicle(self): | |
vehicle = self._vehicle_factory.get_vehicle() | |
vehicle.drive() | |
factory = CarFactory() | |
store = VehicleStore(factory) | |
store.buy_vehicle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment