Java Reference
In-Depth Information
terface that uses an AttributedImpl object to build an attributed version
of our previously defined celestial body class Body :
import java.util.Iterator;
class AttributedBody extends Body
implements Attributed
{
private AttributedImpl attrImpl = new AttributedImpl();
public AttributedBody() {
super();
}
public AttributedBody(String name, Body orbits) {
super(name, orbits);
}
// Forward all Attributed methods to the attrImpl object
public void add(Attr newAttr)
{ attrImpl.add(newAttr); }
public Attr find(String name)
{ return attrImpl.find(name); }
public Attr remove(String name)
{ return attrImpl.remove(name); }
public Iterator<Attr> attrs()
{ return attrImpl.attrs(); }
}
The declaration that AttributedBody extends Body and implements Attrib-
uted defines the contract of AttributedBody . The implementations of all
Body 's methods are inherited from the Body class itself. Each method of
Attributed is implemented by forwarding the invocation to the Attrib-
utedImpl object's equivalent method, returning its value (if any). This
also means that you must add a field of type AttributedImpl to use in the
 
Search WWH ::




Custom Search