Is this what delagates do?

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

I just wrote some code that does the following:

Starting frome existing code that generates a grid of nested boxes
representing the range of indeces in a set of bounded unsigned int values,
e.g., vector<size_t>(3,3) creates a nested grid with 27==(3^3) leaves, and
all the boxes required to border each branch of the tree up to the root.
The details don't matter.

Understand the following to mean there are an arbitrary number child_nodes
at each level, and an arbitrary number of levels. Each child_node has an
associated box, and each box has a box_properties, with a connected
box_widget acting as an observer to state changes in its associated
box_properties:

tree->root_node->child_nodes->child_nodes->...->box->box_properties->box_widget

I wanted a way to uniquely address any given box, and to use that address to
modify the appearance of the widget. I created a class called an
addressed_visitor which is capable of descending the tree to a specified
address using a visitor pattern. When it gets to the specified node, it
detects that it has used all the information in its address which results
in a different behavior frome previous invocation of
addressed_visitor->visit(this).

This time it asks the node to return its associated box. The
addressed_visitor invokes a visit function on the box, but instead of
passing itself, it passes a 'payload' object which knows about box objects.
The visit function on the box invokes the visit function on the payload
which result in the payload calling a visit_properties function on the box
and passing its own payload box_properties_visitor object which knows about
box_properties. The box_properties are protected members of box, but the
box_properties_visitor is granted access within the visit_properties
function. The box_properties_visitor then visits the box_properties object
and calls functions on the box_properties which modify its state, followed
by a fire_properties_changed function which notifies all the registered
listeners of box_properties by passing the properties object to the
listeners. The widget is the only registered listener in this case, and
its handle_properties_changed function applies the changes (by brute force
for now), and refreshes the display.

This may seem overly complicated, and perhaps it is. I will observe that it
worked the first time I ran it, and I have yet to find any errors generated
by the implementation. It's also pretty much a repeated visitor pattern
with the variation that specialized payload visitors are passed at certain
points. Are these specialized payload visitors I'm describing the same
thing as what people call delegates?
 
V

Victor Bazarov

Steven said:
I just wrote some code that does the following:

[...] The details don't matter. [...]

This may seem overly complicated, and perhaps it is. I will observe that it
worked the first time I ran it, and I have yet to find any errors generated
by the implementation. It's also pretty much a repeated visitor pattern
with the variation that specialized payload visitors are passed at certain
points. Are these specialized payload visitors I'm describing the same
thing as what people call delegates?

It seems that your question/issue belongs either to comp.object or to
comp.software.patterns. If you have a C++ language question, we'll be
happy to read about it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top