<snip>
Extract those functions in a separate class, derive from it,
and let the "specific class" be a friend of the base class.
<snip> class ManagedWidget {
friend class WidgetManager;
void do_manage(); // whatever that means...
};
class MyWidget : public ManagedWidget {
void do_some_other_stuff(); // hidden implementation details
public:
void do_client_stuff();
};
class WidgetManager {
...
void manage_a_widget(ManagedWidget &mw) {
mw.do_manage();
}
};
Victor
I see. Thanks.
But there's a problem with this solution. ManagedWidget exposes
everything to the WidgetManager
and if do_manage wants to operate with some private data (which would
always be the case) then that
private data would be accessible by WidgetManager as well.
Unless, unless we made do_manage() a virtual function and defined all
private data in MyWidget.
But that forces us to do a virtual call where it wasn't necessary
before.
Plus, what if I want to restrict client's interface only to a client?
Client part of the Widget's interface
may make sense only to clients, not to managers.
I guess in that case we could use "my firend's friend is not my
friend" thing and have a common base
structure with everything a widget needs to know.
Like this:
struct WidgetBase
{
private:
//define all widget's gadgets
friend class ManagedWidget;
friend class MyWidget;
friend class AccessedWidget
};
class ManagedWidget : virtual WidgetBase
{
friend class WidgetManager
//Specify interface for WidgetManager
void do_manage()
{
//Now we can access all gadgets, which are private in this context
}
};
class AccessedWidget : virtual WidgetBase
{
friend class Client;
//Specify client's interface
void do_client_stuff()
{
//we still can access all the gadgets from here, because we're
friends with WidgetBase
}
};
class MyWidget : ManagedWidget, AccessedWidget
{
public:
void do_something_visible_to_everyone()
{
//we still can access all the gadgets from here, because we're
friends with WidgetBase
}
};
That seems to work, or am I missing something?
Thanks,
Andy.