Thiago Farina
unread,Feb 27, 2013, 2:26:56 PM2/27/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gr...@chromium.org, Anton Vayvod, atwilson, Darin Fisher, Bartosz Fabianowski, Paweł Hajdan, Jr., chromium-dev
On Wed, Feb 27, 2013 at 4:04 PM, Rachel Blum <
gr...@chromium.org> wrote:
> And while it's true that only the class needs to know that it's an observer,
> there's nothing wrong with exposing that it is one. If you really want to
> keep things private, use base::callback. If the observed class insists on
> not using callback, have a trampoline that converts to base::Callback. Or
> fix the observed class.
It isn't that easy as it may sound. Callbacks are fine for one shot
notification, but not when you have more than one.
To make it clear what I think is being discussed here, take the
following example:
class FooView : public views::View,
public views::LinkListener {
public:
// Overridden from views::Listener:
virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
...
};
Versus:
class FooView : public views::View,
public views::LinkListener {
private:
// Overridden from views::Listener:
virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
...
};
So the argument in pro of the second is:
You are NOT supposed to do:
FooView* view = new FooView();
view->LinkClicked(...);
The call to LinkClicked() is responsibility of views framework, and
should be called only from views::Link class in most of the
circumstances, hence private usage is better here IMO, because it
isn't really part of the PUBLIC API exposed by FooView, there are more
interesting methods to be exposed to the clients of FooView than
LinkClicked.
--
Thiago