Robert

28%
Flag icon
Next, define a concrete subclass of the root class for each flavor of the original tagged class. In our example, there are two: circle and rectangle. Include in each subclass the data fields particular to its flavor. In our example, radius is particular to circle, and length and width are particular to rectangle. Also include in each subclass the appropriate implementation of each abstract method in the root class.
Robert
For some cases, an alternative/shortcut of this is to encapsulate the various attributes and behaviors of each flavor in the tag as enum (instead of subclasses). That is, it still might be desirable to enumerate the various flavors (for example, if you expose the possible flavors) and you put the flavor specific implementation ('area()' in this example) in each enum value.
Effective Java
Rate this book
Clear rating
Open Preview