File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
33
4- # http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
4+ """
5+ *What is this pattern about?
6+ The Abstract Factory Pattern serves to provide an interface for
7+ creating related/dependent objects without need to specify their
8+ actual class.
9+ The idea is to abstract the creation of objects depending on business
10+ logic, platform choice, etc.
11+
12+ *What does this example do?
13+ This particular implementation abstracts the creation of a pet and
14+ does so depending on the AnimalFactory we chose (Dog or Cat)
15+ This works because both Dog/Cat and their factories respect a common
16+ interface (.speak(), get_pet() and get_food()).
17+ Now my application can create pets (and feed them) abstractly and decide later,
18+ based on my own criteria, dogs over cats.
19+ The second example allows us to create pets based on the string passed by the
20+ user, using cls.__subclasses__ (the list of sub classes for class cls)
21+ and sub_cls.__name__ to get its name.
22+
23+ *Where is the pattern used practically?
24+
25+ *References:
26+ https://sourcemaking.com/design_patterns/abstract_factory
27+ http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
28+
29+ """
30+
531
6- """Implementation of the abstract factory pattern"""
732import six
833import abc
934import random
You can’t perform that action at this time.
0 commit comments