P
Phil Endecott
Dear Experts,
Say I have an application with various data inputs (files, network
connections, peripherals etc), various data outputs (files, display
etc.) and various intermediate internal data objects. I would like
changes in the inputs to propogate through to the outputs. In my mind,
I'm imagining the dependencies between the objects like "make" dependencies.
There are various ways of doing this, including "push" and "pull"
methods, with various pros and cons. Is anyone aware of any literature
("patterns") describing something like this?
One thought that has occured to me is that C++ has built-in compile-time
dependency graph logic in the multiple inheritance constructors. So,
say I have these objects:
DataSource src;
InternalObj obj1;
InternalObj obj2;
Display disp;
If obj1 and obj2 get their data from the DataSrc, and the Display gets
its data from obj1 and obj2 (i.e. a diamond-shape dependency graph), and
each object has an "update" method, then I can write:
struct make_src {
make_src() { src.update(); }
};
struct make_obj1: make_src {
make_obj1() { obj1.update(); }
};
struct make_obj2: make_src {
make_obj2() { obj2.update(); }
};
struct make_disp: virtual make_obj1, virtual make_obj2 {
make_disp { disp.update(); }
};
Now, when I want to update the display I can just create a temporary
make_disp object, and all of the update() methods will be called in the
right order. (I think. I'm a bit rusty on what the virtual base
classes do. I hope that src.update() gets called only once.)
I bet I'm not the first one to think of this, but google doesn't find
anything - perhaps because of the zillions of hits for extracting
#include dependencies for make from C++ source.
Any thoughts? What else is needed to make this useful? For example,
what's the best way to tag objects with the equivalent of make's timestamps?
Regards,
Phil.
Say I have an application with various data inputs (files, network
connections, peripherals etc), various data outputs (files, display
etc.) and various intermediate internal data objects. I would like
changes in the inputs to propogate through to the outputs. In my mind,
I'm imagining the dependencies between the objects like "make" dependencies.
There are various ways of doing this, including "push" and "pull"
methods, with various pros and cons. Is anyone aware of any literature
("patterns") describing something like this?
One thought that has occured to me is that C++ has built-in compile-time
dependency graph logic in the multiple inheritance constructors. So,
say I have these objects:
DataSource src;
InternalObj obj1;
InternalObj obj2;
Display disp;
If obj1 and obj2 get their data from the DataSrc, and the Display gets
its data from obj1 and obj2 (i.e. a diamond-shape dependency graph), and
each object has an "update" method, then I can write:
struct make_src {
make_src() { src.update(); }
};
struct make_obj1: make_src {
make_obj1() { obj1.update(); }
};
struct make_obj2: make_src {
make_obj2() { obj2.update(); }
};
struct make_disp: virtual make_obj1, virtual make_obj2 {
make_disp { disp.update(); }
};
Now, when I want to update the display I can just create a temporary
make_disp object, and all of the update() methods will be called in the
right order. (I think. I'm a bit rusty on what the virtual base
classes do. I hope that src.update() gets called only once.)
I bet I'm not the first one to think of this, but google doesn't find
anything - perhaps because of the zillions of hits for extracting
#include dependencies for make from C++ source.
Any thoughts? What else is needed to make this useful? For example,
what's the best way to tag objects with the equivalent of make's timestamps?
Regards,
Phil.