|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Decorable
Decorability is the ability to attach extra pieces of information to an object. Although there are no restrictions on how long a decoration may remain attached to an object, the slow speed of most implementations prevent them from being useful for any sort of long-term storage. Their primary use is in labelling an object during the course of an algorithm so that the algorithm may return later in its execution in order to access the label.
Such temporary storage of information is useful in the form of decoration because it allows an algorithm to be written for an existing data structure without having to use secondary data structures and without having to modify the internal representation of the data structure.
This interface defines the methods that a decorable object must implement: those of getting, setting, destroying and checking for a decoration.
The decorations are based on the concept of attribute. The attribute identifies a decoration among all possible ones in a decorated object, and it has to be provided for accessing the decoration itself. Nothing prevents using the same attribute for decoring more than one decorable object. For example, if we are decorating all the positions of a graph we can use just one attribute to retrieve the decoration on all positions.
Method Summary | |
---|---|
ObjectIterator |
attributes()
Returns an iterator over all the attributes attached to this decorable. |
java.lang.Object |
destroy(java.lang.Object attr)
Removes the (attribute, value) entry associated with a certain attribute, attr , from the decorable object. |
java.lang.Object |
get(java.lang.Object attr)
Returns the value in the (attribute, value) entry associated with a certain attribute, attr , in this decorable object. |
boolean |
has(java.lang.Object attr)
Tests whether there is an (attribute, value) entry associated with a certain attribute in this decorable object. |
void |
set(java.lang.Object attr,
java.lang.Object value)
Sets the value in the (attribute, value) entry associated with a certain attribute in this decorable object. |
Method Detail |
---|
void set(java.lang.Object attr, java.lang.Object value) throws InvalidAttributeException
attr
- The attribute to set (and create if necessary)value
- the new value of the attribute in the decorable
object
InvalidAttributeException
- if the attribute is invalid
(i.e. wrong class)java.lang.Object get(java.lang.Object attr) throws InvalidAttributeException
attr
, in this decorable object.
attr
- The attribute of which to attempt to get the value
InvalidAttributeException
- if attr
is not
set or is otherwise invalid (i.e. wrong class)java.lang.Object destroy(java.lang.Object attr) throws InvalidAttributeException
attr
, from the decorable object.
attr
- The attribute to destroy (eliminate)
InvalidAttributeException
- if the attribute is not set
or is otherwise invalid (i.e. wrong class)boolean has(java.lang.Object attr) throws InvalidAttributeException
attr
- The attribute for which to check this decorable
object
InvalidAttributeException
- if attribute is invalid for
some reasonObjectIterator attributes()
ObjectIterator
over all the attributes
attached to this decorable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |