Java Reference
In-Depth Information
4.4.2
Design
The design of the domain representation is straightforward, starting from the
analysis. The classifier is responsible for assigning a category to an item.
Each item (class Item ) is related to a set of features that characterize it. Each
feature has a name and a value; the value is taken from a limited set of
possible values.
Decision point
How do we express the concept that features can assume only a limited set of
values?
We must define the set of possible (or allowed) values; the easiest way is
to provide an array containing them. There are two possible solutions: first
we can provide the array to the constructor of the feature, second we encap-
sulate the array of allowed values into a “type” class. While the former
solution is simpler, the latter is easier to understand and allows us to create
a single object type that is common to all features that have the same type
(i.e. can assume the same set of values).
To adopt the second solution, as shown in Figure 4.5, we define the
FeatureType class that defines the type of the features by providing the set of
allowed values. The features are represented by the class Feature that has a
name and a value. To assign a new value to a feature, the value must be
included in those allowed by the type.
Decision point
How do we represent values of features and categories?
Feature
Item
! features
`` read only pp name : String
0 value
`` read only pp name : String
1 .. n
! type
FeatureType
0 allowedValues
! isAllowed( )
Figure 4.5 Item and feature classes
 
 
Search WWH ::




Custom Search