Responding to McDonagh...
I'm merely talking about a better approach to the naming convention,
than sticking an 'i' in front of the interface.
The problem is that when there is no subclassing the name of the
interface and the name of the class will be semantically the same since
they both abstract the same underlying entity. So one needs to be able
to make a distinction between them for code readability. Using an 'i'
in such cases is relatively painless when deriving one name from the
other so that one can distinguish interface and class references in the
code.
OTOH, such a convention usually isn't needed when defining pure
inherited interfaces because the superclass definition is usually
implied so one won't have superclass references in the code that need to
be distinguished. That was the case in your example where only the
subclasses had class definitions. (Obviously, if one /does/ explicitly
provide superclass class definitions, then one will need to distinguish
between references to the superclass' interface and the superclass itself.)
[Of course one could argue that one should still use a derivative name
for the superclass interface just in case someone adds an explicit
superclass definition in subsequent maintenance. But that becomes even
more of a coding practice debate, so let's not go there.]
That said, the op is using Java, where everything is a polymorphic
dispatch unless explicitly declared otherwise.
We must have very different definitions of polymorphic dispatch.
To have polymorphic dispatch it must be possible to substitute behavior
when a single interface is invoked. If an interface is provided to
access only one class' members, as all of the OP's interfaces did, then
there is no polymorphic substitution when invoking the interface because
there is a 1:1 mapping between interface and class behavior. So
polymorphic dispatch only exists when different classes implement
different specializations of behavior (i.e., the classes are sibling
subclasses). Then the common interface is the interface of their
generalized superclass.
[Actually, there are other forms of polymorphic dispatch in the OO
paradigm but they are related to different constructs, such as
overloading. The form relevant in this context (i.e., behavior
substitution at the interface level) is inclusion polymorphism, which is
only enabled by subclassing.]
Agreed...and in Java you have no choice about this. Interfaces are virtual.
I wasn't showing/using subclassing. Interface implementing yes,
subclassing no. These are different things.
But that is what you /were/ showing relative to the OP's original
problem statement. In the OP's case the interfaces were not shared by
objects from different classes.
Your implication was that CharitableClient and BillableClient both
provided unique implementations of the Client interface. (If they
don't, then I don't understand your example at all.) That makes them
sibling specialization subclasses of a superclass that provides the
<common> Client interface. While languages like Java -- that provide
pure interface inheritance -- don't require the superclass to be defined
explicitly, it is still there implicitly from an OOA/D perspective.
Note that you named your <shared> interface 'Client', which implies a
higher level of abstraction and a generalization relative to the other
class names. IOW, your interface naming convention already abstracts
inheritance from a superclass in a subclassing relationship.
Put it this way. Take away BillableClient so you only have one class to
which the Client interfaces applies, as in the OP's examples. Why
wouldn't the interface name be CharitableClient rather than Client?
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
(e-mail address removed)
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog:
http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH