4 ms·
> In composition (and its on-steroid cousin, delegation), the component/delegate can't "call back" into the aggregating object. It can if you design it to take
by davidcuddeback 7y ago
> In composition (and its on-steroid cousin, delegation), the component/delegate can't "call back" into the aggregating object.
It can if you design it to take a pointer to the aggregating object. Pass this or self or whatever keyword your language uses to the component/delegate and then it can call back to the aggregating object through an explicit pointer. This is more explicit than calling through the object's vtable, which makes the code easier to read IMO, e.g., foo.bar() instead of bar().
- norswap 7y agoHaha, I hesitated to add this precision, I just knew someone was going to make this point. Yep, and sometimes it's worth it to do it like that if only to cleanly separate concerns.