I have kind of a three dimensional problem. lets say you have a class foo and a class bar implementing the same interface. (I only take two classes, but the problem must scale for a large number of classes).
foo_A and foo_B inherits from foo and are very close to each other. Same for bar_A and bar_B. (A's are the same and B's are the same). Here you have two dimensions, and i can smell a bridge pattern, but not entirely.
class my_interface:
@abstract_method
def do_this():
pass
@abstract_method
def do_that():
pass
class foo(my_interface):
@abstract_method
def do_this():
pass
@abstract_method
def do_that():
pass
class bar(my_interface):
@abstract_method
def do_this():
pass
@abstract_method
def do_that():
pass
class foo_A(foo):
def do_this():
# actually_do_something
def do_that():
# actually_do_something
class foo_B(foo):
def do_this():
# actually_do_something
# close_to_foo_A
def do_that():
# actually_do_something
# close_to_foo_A
class bar_A(bar):
def do_this():
# actually_do_something
def do_that():
# actually_do_something
class bar_B(bar):
def do_this():
# actually_do_something
# close_to_bar_A
def do_that():
# actually_do_something
# close_to_bar_A
thing is, that has to scale with numbers of A/B/C...
As for the 3d dimension, I would like to have a state machine implemented with that, so i could have different behaviors of do_that and do_this in each state.
I don't want to have under each foo/bar an inheritance tree with each A/B/C.. and under each of this tree leaf an inheritance tree for each state.
I have read all patterns described in the design patterns bible (http://ift.tt/1tOfdX9) and felt like none of them was a match. Do you know any pattern applying to my situation ?
Aucun commentaire:
Enregistrer un commentaire