Discussion of Alternatives

From Andrey

(Difference between revisions)

Revision as of 06:52, 3 February 2006

In this section, I will consider the alternatives that are used in the existing designs for C++. Suppose Helen has a pager:

class motorola2sx{ public: void call(); };
class working_girl{ public: motorola2sx pager; } Helen;

The task is to provide a mechanism that will enable working_girl class to know that the call() function of its pager member has been called. There can be the following solutions:

1. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class working_girl { public: callpager(); protected: motorola2sx pager; };

2. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

motorola2sx::call() { owner->on_incomingcall(); }

3. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class working_girl
{ 
public: 
	motorola2sx<working_girl> pager; 
	void on_incomingcall();
};

4. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class working_girl_pager : public motorola2sx 
{ public: void call() { callback(); } };
class working_girl
{ public: working_girl_pager pager; friend class working_girl_pager; };

5. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class pager_calls_acceptor { public: virtual void on_call()=0; };
motorola2sx::call() { calls_acceptor->on_call(); }
class working_girl_calls_acceptor : public pager_calls_acceptor { 
	working_girl* girl; 
public: 
	void on_call() { girl->callback(); } 
};

6. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

motorola2sx::call() { broadcast->message(somebody_is _calling, this); }

7. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class working_girl : public motorola2sx { public: void call() { callback(); }};

8. Hide the member and make its interface a subset of the interface of the owner class, not allowing the client to directly access the member:

class motorola2sx{ public: virtual void call()=0; };
class working_girl
{ 
public:
	motorola2sx pager;
	void pager::call() { callback(); }
};

TODO: COMPARISON TABLE