I wanted to have a Group or Aggregate class which could contain some set of objects and operate on them. But, ideally, Group/Aggregate should be generic, and not need to be ``fit'' to each case, so some mechanism for passing on an arbitrary method to each (or selected?) contained object is needed.
A simple solution appeared in the form of a ``default'' method, a last-ditch attempt to resolve a match for a given method. In the current form, I'm using the name ``_default'' for this, though the underscore might not be really necessary. It's pure sugar, no meat, but it is intended to suggest that that method is for internal use only. A symlink is set in the Aggregate/Group class to a ``do'' method which actually does the work. An example:
The group object tries to resolve method foo, but finds no match, but it has a _default method so calls it, passing it the target method and all arguments, options, etc. The Aggregate method has one ordinary method, ``do'', so the above call becomes:
tob group.do foo ...
The do method explicitly calls each contained object with the target foo method, and the goal has been reached.
Having Aggregate._default map via symlink to Aggregate.do is really not even necessary, as the _default method could itself be an executable method. That would leave the method namespace unlimited for grouping arbitrary classes of objects, whereas a method ``do'' would currently not be reachable in the contained objects. (Of course, a ``_default'' method is also not reachable in those objects.)
-- Ken
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wanted to have a Group or Aggregate class which could contain some set of objects and operate on them. But, ideally, Group/Aggregate should be generic, and not need to be ``fit'' to each case, so some mechanism for passing on an arbitrary method to each (or selected?) contained object is needed.
A simple solution appeared in the form of a ``default'' method, a last-ditch attempt to resolve a match for a given method. In the current form, I'm using the name ``_default'' for this, though the underscore might not be really necessary. It's pure sugar, no meat, but it is intended to suggest that that method is for internal use only. A symlink is set in the Aggregate/Group class to a ``do'' method which actually does the work. An example:
tob group.new Aggregate
tob group:ob1.new FooBar
tob group:ob2.new FooBar
tob group:ob3.new FooBar
tob group.foo ...
The group object tries to resolve method foo, but finds no match, but it has a _default method so calls it, passing it the target method and all arguments, options, etc. The Aggregate method has one ordinary method, ``do'', so the above call becomes:
tob group.do foo ...
The do method explicitly calls each contained object with the target foo method, and the goal has been reached.
Having Aggregate._default map via symlink to Aggregate.do is really not even necessary, as the _default method could itself be an executable method. That would leave the method namespace unlimited for grouping arbitrary classes of objects, whereas a method ``do'' would currently not be reachable in the contained objects. (Of course, a ``_default'' method is also not reachable in those objects.)
-- Ken