When using a class to produce a new type,
the class should provide:
methods called
equals,
hashCode,
toString;
if appropriate, a method called
compareTo;
a constructor that initializes the object from a parameter of type
String;
get methods;
set methods (if appropriate);
some means for cloning an object.
Some of these
are needed if objects are to be stored in a collection.
We may be uncertain as to what
clients
will want to do
with objects ...
... Best not
to change the class later
or produce a subclass later.
... Instead, we should provide these things at the outset.
Perhaps, a class is poorly constructed unless it has all of these.
In
'Object-Oriented Design Heuristics',
Arthur Riel introduces the idea of the
minimal public interface.
He says:
‘If the classes that a developer designs and implements
are to be reused by other developers in other applications,
it is often useful to provide a common minimal public interface.
This minimal public interface consists of functionality
that can be reasonably expected from each and every class.’
The canonical object idiom
by Bill Venners
also discusses this subject.