Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class _Car(object):
  2. pass
  3.  
  4.  
  5. class _Bike(object):
  6. pass
  7.  
  8.  
  9. def factory_method(product_type):
  10. if product_type == 'car':
  11. return _Car()
  12. elif product_type == 'bike':
  13. return _Bike()
  14. else:
  15. raise ValueError('Cannot make: {}'.format(product_type))
  16.  
  17.  
  18. def main():
  19. for product_type in ('car', 'bike'):
  20. product = factory_method(product_type)
  21. print(str(product))
  22.  
  23. if __name__ == '__main__':
  24. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement