...
The following utility data structures are designed to handle the situation where an operation has more than 2 or more possible outcomes. While not entirely optimal, these classes show how clever sub-classing can enable one to re-use classes in multiple situations.
* {{IUtilHostAB}} \-\- {{IUtilVisitorAB}}* : AWiki Markup IUtilHostAB
--IUtilVisitorAB
: A host-visitor set that represents a situation where there are +two+ possible outcomes. There are two possible concrete hosts, {{UtilHostA}} and {\[UtilHostB}} and thus the {{IUtilVisitorAB}} visitor has two cases corresponding to these two hosts.Wiki Markup {{IUtilHostABC}} \-\- {{IUtilVisitorABC}} : A host-visitor set that represents a situation where there are +three+ possible outcomes. There are three possible concrete hosts, {{UtilHostA}}, {\[UtilHostB}} and {{UtilHostC}} and thus the {{IUtilVisitorABC}} visitor has three cases corresponding to these three hosts.
- There are two possible concrete hosts,
UtilHostA
andUtilHostB
and thus theIUtilVisitorAB
visitor has two cases corresponding to these two hosts. IUtilHostABC
--IUtilVisitorABC
: A host-visitor set that represents a situation where there are three possible outcomes. There are three possible concrete hosts,UtilHostA
,UtilHostB
andUtilHostC
and thus theIUtilVisitorABC
visitor has three cases corresponding to these three hosts.IUtilHostABCD
--IUtilVisitorABCD
: A host-visitor set that represents a situation where there are four possible outcomes. There are four possible concrete hosts,UtilHostA
,UtilHostB
,UtilHostC
andUtilHostD
and thus theIUtilVisitorABCD
visitor has four cases corresponding to these three hosts.
Typically, a method returns a value of type IUtilHostAB/C/D
depending on how many possibilities there are. For instance, a single reduction pass on the Sudoku board would result in a value of IUtilHostABCD, corresponding to the 4 possible outcomes for the board: being still reducible, irreducible, solved or unsolvable.
The caller of such a method need only to simply delegate to the returned value by having the returned value accept the proper visitor. Suppose the method my3OutcomeMethod} has three possible outcomes, so it returns an {{IUtilHostABC
object. All we need to do is to delegate to the returned value of the method:
Code Block |
---|
my3OutcomeMethod().accept(new IUtilVisitorABC() {...})
|
Model-View-Controller Architecture
...