Convenient approach to composite pattern in C++

Started by
14 comments, last by Brain 9 years, 1 month ago

another candidate is the almost-never overloaded comma operator.


OK, OK, I know you guys are just having fun, but I'm about to get an aneurysm. tongue.png

Sean Middleditch – Game Systems Engineer – Join my team!

Advertisement
All of you should read Eric Neibler's blog, as well as check out Sean Parent's Adobe Source Library. Parent has the concept of (I can't remember his name for them to save my life) "range adaptors" and Neibler's views can do similar things, such that you can write:

algorithm(container, /*stuff*/, &element::method)
and have things work, consistently and predictably, for _every_ algorithm and not just for_each.

Sean Middleditch – Game Systems Engineer – Join my team!

Indeed, I had some tabs left open on Neibler's page to look at today.

I'll check out Parent's library too. Thanks for that.

throw table_exception("(? ???)? ? ???");

I would be tempted to use << as a stream operator:


Notifier(listenerList) << somedata << moredata;

The side effects and behaviour of these operators are better documented and the syntax makes sense as it is similar to iostream, just my 2 cents worth...

Notifier would be a simple class like:


typedef vector<Interested*> Notifiable;

class Notifier 
{
    Notifiable * n;
public: 
    Notifier (Notifiable *n): n(n) { }
    operator<<(...) { /* overloaded code here to send data to Notifiable */ }
};

Hang on, why do we need this to be a one-liner, anyway?

Hang on, why do we need this to be a one-liner, anyway?

Because abstractions are cool :D

Nah, personal preference, I prefer common actions like sending a message to an observer to be as simple as possible to do, so long as the implementation is abstracted away nicely and we'll documented it's all good...

This topic is closed to new replies.

Advertisement