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:
tylerlaberge
2016-08-28 14:25:13 -04:00
parent e02d089b37
commit b3ca14d1df
3 changed files with 15 additions and 15 deletions

View File

@@ -5,9 +5,8 @@ class Director(object, metaclass=ABCMeta):
""" """
Abstract director class, responsible for using a builder to fully construct an object. Abstract director class, responsible for using a builder to fully construct an object.
Part of the 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}
External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
""" """
def __init__(self): def __init__(self):
@@ -19,7 +18,7 @@ class Director(object, metaclass=ABCMeta):
@abstractmethod @abstractmethod
def construct(self): 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. 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 return self.builder.constructed_object
class Builder(object): class Builder(object, metaclass=ABCMeta):
""" """
Abstract builder class, responsible for constructing various pieces of an object. Abstract builder class, responsible for constructing various pieces of an object.
Part of the 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}
External Builder Pattern documentation: U{https://en.wikipedia.org/wiki/Builder_pattern}
""" """
def __init__(self, constructed_object): def __init__(self, constructed_object):

View File

@@ -7,7 +7,8 @@ class Factory(object, metaclass=ABCMeta):
All Factories should inherit this class and overwrite the create method. 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 @abstractmethod
def create(self, **kwargs): def create(self, **kwargs):
@@ -21,11 +22,12 @@ class Factory(object, metaclass=ABCMeta):
pass 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): def __init__(self):
""" """
@@ -55,4 +57,4 @@ class AbstractFactory(Factory):
@type key: str @type key: str
@param factory: The factory to register to the key. @param factory: The factory to register to the key.
""" """
self._factories[str(key)] = factory() self._factories[str(key)] = factory

View File

@@ -79,8 +79,8 @@ class AbstractFactoryTestCase(TestCase):
class AnimalFactory(AbstractFactory): class AnimalFactory(AbstractFactory):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._register('cat', CatFactory) self._register('cat', CatFactory())
self._register('dog', DogFactory) self._register('dog', DogFactory())
def create(self, animal_type): def create(self, animal_type):
return self._factories[animal_type].create() return self._factories[animal_type].create()