Automating Google Workspace (GWS) & more with Apps Script
Hw8 GoF state, strategy, tempate method, visitor
1. UTAH STATE UNIVERSITY
COMPUTER SCIENCE
CS-7350 Reading Assignment
GoF Patterns: State, Strategy, Template Method and Visitor
Jorge Edison Lascano
Spring 2012
01-27-2012
STATE, STRATEGY, TEMPLATE METHOD and VISITORGoF PATTERNS
State, is it really easy to add new states?
It is not easy, since ConcreteState objectsbehavior depends on each other, in this sense, the
complexity of selecting the subsequent state is sparsed among all objects (the intelligence is
distributed). If we need to model this behavior, a Multi Object State Machine Diagram will be
needed, and it can become a very complex task if more states are needed.Besides,if transitions
are not controlled by some component, certain kind of anarchy may occur. As ConcreteStates are
supposed to work as a team, Observer pattern could be a possible solution that allows notifying
when object changed its state or a new object appears, aflag can be used to indicate the active
state in time, it is still not easy to increase states though, but its collaborative behavior is better
controlled.
In Strategy, the client still has to take the decision on which object to use. Template Method, is
difficult to maintain when ConcreteClasses are increased and worse if levels of hierarchy are
added. Visitor, is a wrapper with special permissions that breaks some encapsulation of the
visitees.