Java Reference
In-Depth Information
It is a sad (but interesting) fact that no language, whether designed for programming a com-
puter or evolved by some human culture, can describe the world in a completely natural fash-
ion. [ 25 ] Those who have studied other (human) languages know that there are things that can
be expressed easily in one that are difficult or impossible to express in another. Metaphor and
poetry are, on some accounts, attempts to say the unsayable. Philosophers such as Kant, He-
gel, and Heidegger push language to such extremes that it isn't clear what they are saying.
If human language can't capture the world, we certainly should not expect programming lan-
guages to do any better. [ 26 ] Programming languages provide an abstraction of the computer
that can be used to model things in the world, but there comes a point at which the expressive-
ness of the language is inadequate for the job of directly mapping the world and the language.
When that happens, a good designer will recognize the mismatch, and make the trade-offs as
best he can. Pushing the language beyond its expressive capabilities generally leads to bad
design. You may be able to capture this part of the world in the dynamic structure of the pro-
gram, but it won't look elegant in the language.
We will capture our relation between Player objects and the various statistic-gathering ob-
jects by using a form of delegation. We will extend our definition of the Player interface in
such a way that we can obtain the various roles that such a player might have. To do this, we
will add methods that will return an object supporting the appropriate interface for each of the
roles. An example would look something like:
/**
* Return a {@code Batter} object if this player has
* any at-bats registered. Otherwise, return
* {@code null}.
*/
Batter asBatter();
/**
* Return a {@code Fielder} object representing the
* Fielding statistics for this player, if the player
* has any such statistics. Otherwise, return null.
*/
Fielder asFielder();
/**
* Return a {@code Catcher} object representing
* the catching statistics of this player, if the
* player is a catcher, otherwise return null.
*/
Catcher asCatcher();
 
 
Search WWH ::




Custom Search