Skip to content
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ script:
# Run tests
- PYTHONPATH=. nosetests -s -v --with-doctest --with-cov --cover-package . --logging-level=INFO -v .
# Actually run all the scripts, contributing to coverage
- ./run_all.sh
- PYTHONPATH=. ./run_all.sh
# for now failure in flaking is ignored
- flake8 *py || echo "PEP8 the code"

Expand Down
73 changes: 40 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,59 @@ __Creational Patterns__:

| Pattern | Description |
|:-------:| ----------- |
| [abstract_factory](abstract_factory.py) | use a generic function with specific factories |
| [borg](borg.py) | a singleton with shared-state among instances |
| [builder](builder.py) | instead of using multiple constructors, builder object receives parameters and returns constructed objects |
| [factory_method](factory_method.py) | delegate a specialized function/method to create instances |
| [lazy_evaluation](lazy_evaluation.py) | lazily-evaluated property pattern in Python |
| [pool](pool.py) | preinstantiate and maintain a group of instances of the same type |
| [prototype](prototype.py) | use a factory and clones of a prototype for new instances (if instantiation is expensive) |
| [abstract_factory](creational/abstract_factory.py) | use a generic function with specific factories |
| [borg](creational/borg.py) | a singleton with shared-state among instances |
| [builder](creational/builder.py) | instead of using multiple constructors, builder object receives parameters and returns constructed objects |
| [factory_method](creational/factory_method.py) | delegate a specialized function/method to create instances |
| [lazy_evaluation](creational/lazy_evaluation.py) | lazily-evaluated property pattern in Python |
| [pool](creational/pool.py) | preinstantiate and maintain a group of instances of the same type |
| [prototype](creational/prototype.py) | use a factory and clones of a prototype for new instances (if instantiation is expensive) |

__Structural Patterns__:

| Pattern | Description |
|:-------:| ----------- |
| [3-tier](3-tier.py) | data<->business logic<->presentation separation (strict relationships) |
| [adapter](adapter.py) | adapt one interface to another using a white-list |
| [bridge](bridge.py) | a client-provider middleman to soften interface changes |
| [composite](composite.py) | encapsulate and provide access to a number of different objects |
| [decorator](decorator.py) | wrap functionality with other functionality in order to affect outputs |
| [facade](facade.py) | use one class as an API to a number of others |
| [flyweight](flyweight.py) | transparently reuse existing instances of objects with similar/identical state |
| [front_controller](front_controller.py) | single handler requests coming to the application |
| [mvc](mvc.py) | model<->view<->controller (non-strict relationships) |
| [proxy](proxy.py) | an object funnels operations to something else |
| [3-tier](structural/3-tier.py) | data<->business logic<->presentation separation (strict relationships) |
| [adapter](structural/adapter.py) | adapt one interface to another using a white-list |
| [bridge](structural/bridge.py) | a client-provider middleman to soften interface changes |
| [composite](structural/composite.py) | encapsulate and provide access to a number of different objects |
| [decorator](structural/decorator.py) | wrap functionality with other functionality in order to affect outputs |
| [facade](structural/facade.py) | use one class as an API to a number of others |
| [flyweight](structural/flyweight.py) | transparently reuse existing instances of objects with similar/identical state |
| [front_controller](structural/front_controller.py) | single handler requests coming to the application |
| [mvc](structural/mvc.py) | model<->view<->controller (non-strict relationships) |
| [proxy](structural/proxy.py) | an object funnels operations to something else |

__Behavioral Patterns__:

| Pattern | Description |
|:-------:| ----------- |
| [chain](chain.py) | apply a chain of successive handlers to try and process the data |
| [catalog](catalog.py) | general methods will call different specialized methods based on construction parameter |
| [chaining_method](chaining_method.py) | continue callback next object method |
| [command](command.py) | bundle a command and arguments to call later |
| [mediator](mediator.py) | an object that knows how to connect other objects and act as a proxy |
| [memento](memento.py) | generate an opaque token that can be used to go back to a previous state |
| [observer](observer.py) | provide a callback for notification of events/changes to data |
| [publish_subscribe](publish_subscribe.py) | a source syndicates events/data to 0+ registered listeners |
| [registry](registry.py) | keep track of all subclasses of a given class |
| [specification](specification.py) | business rules can be recombined by chaining the business rules together using boolean logic |
| [state](state.py) | logic is organized into a discrete number of potential states and the next state that can be transitioned to |
| [strategy](strategy.py) | selectable operations over the same data |
| [template](template.py) | an object imposes a structure but takes pluggable components |
| [visitor](visitor.py) | invoke a callback for all items of a collection |
| [chain](behavioral/chain.py) | apply a chain of successive handlers to try and process the data |
| [catalog](behavioral/catalog.py) | general methods will call different specialized methods based on construction parameter |
| [chaining_method](behavioral/chaining_method.py) | continue callback next object method |
| [command](behavioral/command.py) | bundle a command and arguments to call later |
| [iterator](behavioral/iterator.py) | traverse a container and access the container's elements |
| [mediator](behavioral/mediator.py) | an object that knows how to connect other objects and act as a proxy |
| [memento](behavioral/memento.py) | generate an opaque token that can be used to go back to a previous state |
| [observer](behavioral/observer.py) | provide a callback for notification of events/changes to data |
| [publish_subscribe](behavioral/publish_subscribe.py) | a source syndicates events/data to 0+ registered listeners |
| [registry](behavioral/registry.py) | keep track of all subclasses of a given class |
| [specification](behavioral/specification.py) | business rules can be recombined by chaining the business rules together using boolean logic |
| [state](behavioral/state.py) | logic is organized into a discrete number of potential states and the next state that can be transitioned to |
| [strategy](behavioral/strategy.py) | selectable operations over the same data |
| [template](behavioral/template.py) | an object imposes a structure but takes pluggable components |
| [visitor](behavioral/visitor.py) | invoke a callback for all items of a collection |

__Fundamental Patterns__:

| Pattern | Description |
|:-------:| ----------- |
| [delegation_pattern](fundamental/delegation_pattern.py) | an object handles a request by delegating to a second object (the delegate) |

__Others__:

| Pattern | Description |
|:-------:| ----------- |
| [blackboard](blackboard.py) | (architectural model, assemble different sub-system knowledge to build a solution, AI approach - non gang of four pattern) |
| [graph_search](graph_search.py) | (graphing algorithms, not design patterns) |
| [blackboard](other/blackboard.py) | architectural model, assemble different sub-system knowledge to build a solution, AI approach - non gang of four pattern |
| [graph_search](other/graph_search.py) | graphing algorithms - non gang of four pattern |
| [hsm](other/hsm/hsm.py) | hierarchical state machine - non gang of four pattern |
Empty file added behavioral/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added creational/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added fundamental/__init__.py
Empty file.
File renamed without changes.
Empty file added other/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added other/hsm/__init__.py
Empty file.
File renamed without changes
File renamed without changes
File renamed without changes.
4 changes: 2 additions & 2 deletions run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ if which coverage > /dev/null; then
else
COVERAGE=''
fi
for f in [^_]*py; do
python $COVERAGE $f || failed+=" $f"
for f in */[^_]*py; do
PYTHONPATH=. python $COVERAGE $f || failed+=" $f"
echo "I: done $f. Exit code $?"
done;

Expand Down
File renamed without changes.
Empty file added structural/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from abstract_factory import PetShop, Dog, Cat, DogFactory, CatFactory
from creational.abstract_factory import PetShop, Dog, Cat, DogFactory, CatFactory
import sys

if sys.version_info < (2, 7):
Expand Down
2 changes: 1 addition & 1 deletion test_adapter.py → tests/test_adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from adapter import Dog, Cat, Human, Car, Adapter
from structural.adapter import Dog, Cat, Human, Car, Adapter
import sys

if sys.version_info < (2, 7):
Expand Down
2 changes: 1 addition & 1 deletion test_borg.py → tests/test_borg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from borg import Borg, YourBorg
from creational.borg import Borg, YourBorg
import sys

if sys.version_info < (2, 7):
Expand Down
2 changes: 1 addition & 1 deletion test_bridge.py → tests/test_bridge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bridge import DrawingAPI1, DrawingAPI2, CircleShape
from structural.bridge import DrawingAPI1, DrawingAPI2, CircleShape
from sys import version_info

if version_info < (2, 7): # pragma: no cover
Expand Down
8 changes: 4 additions & 4 deletions test_command.py → tests/test_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from command import MoveFileCommand
from behavioral.command import MoveFileCommand
import os, shutil, subprocess, sys

if sys.version_info < (2, 7):
Expand All @@ -25,8 +25,8 @@ def setUpClass(self):
- get the temporary test directory
- and initializes the command stack.
"""
os.mkdir('test_command')
open('test_command/foo.txt', 'w').close()
os.mkdir('tests/test_command')
open('tests/test_command/foo.txt', 'w').close()
self.__get_test_directory()
self.command_stack = []
self.command_stack.append(MoveFileCommand(os.path.join(self.test_dir, 'foo.txt'), os.path.join(self.test_dir, 'bar.txt')))
Expand Down Expand Up @@ -54,7 +54,7 @@ def tearDownClass(self):
"""
Remove the temporary directory /test_command and its content.
"""
shutil.rmtree('test_command')
shutil.rmtree('tests/test_command')

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion test_flyweight.py → tests/test_flyweight.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flyweight import Card
from structural.flyweight import Card
from sys import version_info

if version_info < (2, 7): # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion test_hsm.py → tests/test_hsm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from hsm import HierachicalStateMachine, UnsupportedMessageType,\
from other.hsm.hsm import HierachicalStateMachine, UnsupportedMessageType,\
UnsupportedState, UnsupportedTransition, Active, Standby, Suspect, Failed
from sys import version_info

Expand Down
2 changes: 1 addition & 1 deletion test_observer.py → tests/test_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys
from io import StringIO
from observer import Subject, Data, DecimalViewer, HexViewer
from behavioral.observer import Subject, Data, DecimalViewer, HexViewer

if sys.version_info < (2, 7):
import unittest2 as unittest
Expand Down
2 changes: 1 addition & 1 deletion test_proxy.py → tests/test_proxy.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from proxy import Proxy, NoTalkProxy
from structural.proxy import Proxy, NoTalkProxy
import sys
from time import time

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from sys import version_info
from publish_subscribe import Provider, Publisher, Subscriber
from behavioral.publish_subscribe import Provider, Publisher, Subscriber

if version_info < (2, 7): # pragma: no cover
import unittest2 as unittest
Expand Down
2 changes: 1 addition & 1 deletion test_state.py → tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from state import Radio
from behavioral.state import Radio
import sys

if sys.version_info < (2, 7):
Expand Down
2 changes: 1 addition & 1 deletion test_strategy.py → tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_print_output(self):
The expected_output is equivalent to the output on the command
line when running 'python strategy.py'.
"""
output = subprocess.check_output(["python", "strategy.py"])
output = subprocess.check_output(["python", "behavioral/strategy.py"])
expected_output = os.linesep.join([
'Strategy Example 0',
'Strategy Example 1 from execute 1',
Expand Down