David Bolen wrote:
> James Wilson <> writes:
>
>
>>I think you're on the right track though. Composition is a good way.
>>
>>public interface Player
>> methods of the interface
>>
>>public interface Dealer extends Player
>> extra methods of the interface
>>
>>public interface GUIPlayer extends Player
>> extra methods of the interface
>>
>>public interface GUIDealer extends Dealer, GUIPlayer
>> extra methods of the interface
>>
>>
>>And then create concrete implementations of each of these
>>interfaces.
>
>
> Yeah, that's what I figured - unfortunately in this example I
> duplicate even more effort (implementations) than just single
> inheriting from GUIPlayer in that I have to duplicate both the
> GUIPlayer and Dealer logic in GUIDealer. If I inherit from GUIPlayer
> than I just have to reimplement the original Dealer/Player logic
> differences.
>
> The rub is that the only practical between GUIDealer and Dealer is the
> difference created between GUIPlayer and Player - so other than
> wanting to inherit that difference, any other code I write as part of
> GUIDealer is duplication that I have to maintain.
I came late to this discussion, so likely I'm missing something, but it
sure seems like Dealer is a role that a Player can have more than it is
a specific type of Player. The design is more loosely coupled if Dealer
does not extend Player but instead is associated with a Player. Among
the advantages this would provide is that there would be no need for
different kinds of Dealers in parallel with different kinds of Players
(i.e. you could do away with GUIDealer altogether).
Also, interfaces are very useful in many situations, but not so useful
if there is no room for alternative implementations. In this particular
case, if Player is a class then it can expose a package-private API for
a seperate Dealer object to use, but if it is an interface then all its
methods are implictly public.
John Bollinger