473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Is this what delagates do?

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?

--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations, but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.

Jul 22 '05 #1
1 1158
Steven T. Hatton wrote:
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.
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
9
by: Alan Silver | last post by:
hello, I am writing my first real ASP.NET application, but am getting a bit confused with ADO.NEt and the best way to use it. My old method (with Classic ASP) was to have a function that you...
3
by: MikeY | last post by:
Hi everyone, I'm trying to figure out, on my windows form, of what is the best way to add various custom controls at various times during run-time. The problem is that they will need to be in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.