Skip to content

Instantly share code, notes, and snippets.

@ZoranPandovski
Created October 7, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZoranPandovski/38f73e4102881095ff4f3fb18170e12f to your computer and use it in GitHub Desktop.
Save ZoranPandovski/38f73e4102881095ff4f3fb18170e12f to your computer and use it in GitHub Desktop.
Abstract Factory in python
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