...
- Shirts - represents shirts of various types
- Pants - represents pants of various types
- Socks - represents socks of various types
- NullGarment - represents the absence of a garment, such as one might get on a failed search for a garment.
All Garments have an "adjective" field that is used to differentiate different instances of Shirts and Pants and Socks, e.g. a "blue" Shirt vs. a "red" Shirt.
Garments support a visitor, GarmentVisitor, which has cases for each type of visitor. Never test for the type of a Garment object! Always delegate to it by having the garment object accept a visitor whose different cases provide the garment-type-dependent processing you desire.
...
Code Block |
---|
GarmentVisitor isSockGarmentVisitor = new AGarmentVisitor<String>("Not a Sock!") { public String forSocks(Socks sockHost) { return "Got some socks!"; } } aShirt.accept(isSockGarmentVisitor) --> "Not a Sock!" aPants.accept(isSockGarmentVisitor) --> "Not a Sock!" aNullGarment.accept(isSockGarmentVisitor) --> "Not a Sock!" aSock.accept(isSockGarmentVisitor) --> "Got some socks!" |
The SameTypeGarmentVisitor is a utility visitor that can be used to return a true or false if two Garment objects are the same type, i.e. a Shirt and a Shirt or a Pants and a Pants, regardless of their "adjectives".
Lists package
BiLists are used to represent the various piles of clothes.
!uml_list.png|align=center!
sadfsdf
sadfsdaf