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
(e.g., a list).
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 the required features at the outset.
Perhaps, a class is poorly constructed unless it has all of these.
The term
minimal public interface
is taken from
Arthur Riel's book
'Object-Oriented Design Heuristics'
([13]).
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'
([22])
by Bill Venners
also discusses this subject.