Sometimes code that is used to modify and
organize
Construct object
data can be easily generalized and reused with objects of other
classes. It would be a good idea then to instead put it into a
subclass of the Behavior base class instead. Another reason you
might want to pull it out into a Behavior class is if the organization
and behavior uses a lot of memory and will only be used by a few
instances of that class. You can bring that required memory into
a Behavior object which you can then attach to the Construct object to
give it
the desired behavior and then get rid of the Behavior object (and in
turn the associated memory) when you no longer need or want it.
This makes sure that objects that do not take advantage of that
behavior are not bogged down with the requisite memory. Like the
Construct abstract base class, a plain instance of the Behavior class
in
and of itself is not interesting and the Behavior class is meant to be
subclassed.
There are two main methods that can be
overridden in
a Behavior
class. The first is the - (bool)
Set:(Construct*)a message which
is called when a
Behavior object is attached to a Construct object. The second is
the - (void) Act message which is called
every time the Behavior
objects
are
enacted on the object they are attached to which is typically during
the organization maintenance phase of that Construct object if it is
connected to the world's Construct tree.
Sometimes code that is used to modify and organize Construct object data can be easily generalized and reused with objects of other classes. It would be a good idea then to instead put it into a subclass of the Behavior base class instead. Another reason you might want to pull it out into a Behavior class is if the organization and behavior uses a lot of memory and will only be used by a few instances of that class. You can bring that required memory into a Behavior object which you can then attach to the Construct object to give it the desired behavior and then get rid of the Behavior object (and in turn the associated memory) when you no longer need or want it. This makes sure that objects that do not take advantage of that behavior are not bogged down with the requisite memory. Like the Construct abstract base class, a plain instance of the Behavior class in and of itself is not interesting and the Behavior class is meant to be subclassed.
There are two main methods that can be overridden in a Behavior class. The first is the - (bool) Set:(Construct*)a message which is called when a Behavior object is attached to a Construct object. The second is the - (void) Act message which is called every time the Behavior objects are enacted on the object they are attached to which is typically during the organization maintenance phase of that Construct object if it is connected to the world's Construct tree.