Re: what is encapsulation in an interface ?
On 12/30/2010 06:58 AM, gk wrote:
what is encapsulation in an interface ?
interface Bicycle {
void changeCadence(int newValue); // Do you call this
encapsulation ?
void changeGear(int newValue); // Do you call this
encapsulation ?
void speedUp(int increment); // Do you call this
encapsulation ?
void applyBrakes(int decrement); // Do you call this
encapsulation ?
}
Encapsulation means that functionality is entirely enclosed within a thing,
and that details of that functionality are hidden from clients outside that thing.
I do not see how the term applies to an interface /per se/. Interfaces do not
contain any functionality to encapsulate. The encapsulation is in the
implementation classes of that interface type. Each different implementor
encapsulates its implementation; clients of the type (the interface and its
subtypes, that is) do not concern themselves (much) with details of the
implementation.
Perhaps it breaks encapsulation, but non-functional implementation
characteristics can determine the choice of implementation type for an
interface. For example, the performance characteristics of 'TreeList' and
'ArrayList' differ, although both encapsulate implementations of 'List'. That
difference could drive the choice of which 'List' to use.
However, as stated your question is difficult to make sense of. I wouldn't
say exactly that there is "encapsulation in an interface" but in the
implementing classes.
What exactly are you trying to figure out and why?
--
Lew
Ceci n'est pas une pipe.