Re: Naming conventions for Interface + Implementation classes?
Peter Duniho wrote:
Reposting to include c.l.j.p because I didn't notice the original
message had idiotically been set for follow-ups only to c.l.j.h.
Robin Wenger has had pushback on the cross-posting issue several times
before, but apparently has decided not to comply with the multiple
requests to clean up their act.
Robin Wenger wrote:
As I noticed there are two different naming conventions for an Interface=
+Implementation pair:
As Pete noted, neither is really conventional.
1.) MyClass (=Interface) + MyClassImpl (=Implementation)
or
2.) IMyClass (=Interface) + MyClass (=Implementation)
The first one is (AFAIK) from Sun Who defined originally the second o=
ne?
Idiots.
What is recommended (for which scenario)?
The second one, never. The use of 'Impl' for an implementing class is
sometimes used pedagogically when the topic is interfaces and their
implementations. In production code, both of those so-called
"conventions" violate the principle of names that make sense in the
problem domain.
Peter Duniho wrote:
I don't think you'll find anyone using the word "Class" in an interface
name, nor the suffice "Impl" in the name of a class that implements an
interface.
Unless they use "Impl" in a discussion to emphasize coding principles,
but generally Pete has the right of it.
So on the face of the it, the question doesn't make much sense.
In Java, what I often see with respect to interfaces and implementations
are names like "MyInterface" and "MySpecificKindOfMyInterface". E.g.
List vs ArrayList, Set vs HashSet, etc.
That said, if you're mainly asking about whether to use a leading 'I' on
interface names or not, hard-core Java purists are unlikely to find that
kosher. It's a convention followed in .NET and in the Windows API for
COM interfaces (and possibly Delphi, and other languages=85), but I've
never seen it in any "official" Java code.
The Sun conventions suggest the use of names that are sensible in the
problem domain.
"Class names should be nouns, in mixed case with the first letter of
each internal word capitalized. Try to keep your class names simple
and descriptive. Use whole words-avoid acronyms and abbreviations
(unless the abbreviation is much more widely used than the long form,
such as URL or HTML)."
<http://www.oracle.com/technetwork/java/
codeconventions-135099.html#367>
There's nothing in there about using "Class" (TERRIBLE idea!) or
"Impl" as part of a type name, and the examples there don't show such
a thing.
Naming a type (forget class or interface - think "type") with
implementation details ("I" for interface, "Impl" for class) violates
the O-O principle to hide implementation and is a stupid idea. It
benefits nothing, it imposes extra work if you change implementation
(one of the motivators for black-boxing implementation) to avoid
misleading nomenclature, and it bespeaks a lack of critical-thinking
capacity.
--
Lew