In addition, when designing it can sometimes help to group a number of classes together that may share some common purpose with an interface that has no methods.
You may not actively use the common interface, but from a design aspect it can help to clarify a group of classes and provide less clutter in a UML class diagram for example. Also, you may use the interface later on when the implementing classes become more defined and they do start to exhibit common behaviour that you want to enforce in the interface contract.
A bit of a "wooly" reply, but the "marker" interfaces help me when understanding large class diagrams.
SomeObject o = new SomeObject(); SomeObject ref = (SomeObject)(o.clone());
why is the castin g done? because 'o' is a SomeObject reference?
This has nothing to do with interfaces as such. clone() returns something of type Object and you can not assign something of type Object to the ref of type SomeObject, even when you know it is of type SomeObject. Therefore you have to tell the compiler you know what you are doing by adding the cast to SomeObject.
Ernest Friedman-Hill
,
author and iconoclast
staff