Added external usage documentation links.
Changed abstract factory register method to take in a factory isntance as an argument as opposed to a factory class.
This commit is contained in:
@@ -5,9 +5,8 @@ class Director(object, metaclass=ABCMeta):
|
||||
"""
|
||||
Abstract director class, responsible for using a builder to fully construct an object.
|
||||
|
||||
Part of the builder pattern.
|
||||
|
||||
External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Creational-Pattern-Usage}
|
||||
- External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@@ -19,7 +18,7 @@ class Director(object, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def construct(self):
|
||||
"""
|
||||
Abstract class for fully constructing an object.
|
||||
Abstract method for fully constructing an object.
|
||||
|
||||
Concrete implementations should override this and use a builder to construct the object.
|
||||
|
||||
@@ -36,13 +35,12 @@ class Director(object, metaclass=ABCMeta):
|
||||
return self.builder.constructed_object
|
||||
|
||||
|
||||
class Builder(object):
|
||||
class Builder(object, metaclass=ABCMeta):
|
||||
"""
|
||||
Abstract builder class, responsible for constructing various pieces of an object.
|
||||
|
||||
Part of the builder pattern.
|
||||
|
||||
External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Creational-Pattern-Usage}
|
||||
- External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
|
||||
"""
|
||||
|
||||
def __init__(self, constructed_object):
|
||||
|
||||
@@ -7,7 +7,8 @@ class Factory(object, metaclass=ABCMeta):
|
||||
|
||||
All Factories should inherit this class and overwrite the create method.
|
||||
|
||||
External Factory Pattern documentation: U{https://en.wikipedia.org/wiki/Factory_method_pattern}
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Creational-Pattern-Usage}
|
||||
- External Factory Pattern documentation: U{https://en.wikipedia.org/wiki/Factory_method_pattern}
|
||||
"""
|
||||
@abstractmethod
|
||||
def create(self, **kwargs):
|
||||
@@ -21,11 +22,12 @@ class Factory(object, metaclass=ABCMeta):
|
||||
pass
|
||||
|
||||
|
||||
class AbstractFactory(Factory):
|
||||
class AbstractFactory(Factory, metaclass=ABCMeta):
|
||||
"""
|
||||
Abstract Factory Class.
|
||||
Abstract Factory Class as part of the AbstractFactory design pattern.
|
||||
|
||||
External Abstract Factory Pattern documentation: U{https://en.wikipedia.org/wiki/Abstract_factory_pattern}
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Creational-Pattern-Usage}
|
||||
- External Abstract Factory Pattern documentation: U{https://en.wikipedia.org/wiki/Abstract_factory_pattern}
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
@@ -55,4 +57,4 @@ class AbstractFactory(Factory):
|
||||
@type key: str
|
||||
@param factory: The factory to register to the key.
|
||||
"""
|
||||
self._factories[str(key)] = factory()
|
||||
self._factories[str(key)] = factory
|
||||
|
||||
@@ -79,8 +79,8 @@ class AbstractFactoryTestCase(TestCase):
|
||||
class AnimalFactory(AbstractFactory):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._register('cat', CatFactory)
|
||||
self._register('dog', DogFactory)
|
||||
self._register('cat', CatFactory())
|
||||
self._register('dog', DogFactory())
|
||||
|
||||
def create(self, animal_type):
|
||||
return self._factories[animal_type].create()
|
||||
|
||||
Reference in New Issue
Block a user