Path: utzoo!attcan!uunet!meaddata!gordon From: gordon@meaddata.com (Gordon Edwards) Newsgroups: comp.lang.c++ Subject: Re: Delegation through a pointer Message-ID: <1755@meaddata.meaddata.com> Date: 25 Oct 90 12:28:59 GMT References: <11578@gremlin.nrtc.northrop.com> Sender: usenet@meaddata.com Reply-To: gordon@meaddata.com (Gordon Edwards) Distribution: comp Organization: Mead Data Central, Dayton OH Lines: 60 In article <11578@gremlin.nrtc.northrop.com>, kkenny@wind.nrtc.northrop.com (Kevin B. Kenny KE9TV) writes: |> |> In Bjarne Stroustrup's paper, ``Multiple Inheritance for C++,'' |> Stroustrup discusses an extension of the inheritance mechanism that |> allows a class to inherit froman object identified by pointer: i.e., |> [example deleted. -gordon] |> |> This extension never made it into the language. I'm curious what its |> status is: were there insuperable problems with it? What other way is |> provided for the designer of a class B to specify that B wants to |> inherit from A *or from any of A's derived classes*? |> C++ supports a limited form of delegation. Operations can be forwarded to delegate objects. The following examples were taken from a pilot of AT&T's "Object Oriented Design for C++", that I attended during the summer. class Employee { ... void SortMail(Mail); void SignVouchers(Vouchers); ... }; class Manager { Employee* maildelegate; Employee* voucherdelegate; public: void sortMail(Mail); void signVouchers(Vouchers); Manager(Employee* mailsorter = 0, Employee* vouchersigner = 0); }; Manager::Manager(Employee* mailsorter, Employee* vouchersigner) { maildelegate = mailsorter; voucherdelegate = vouchersigner; } void Manager::sortMail(Mail m) { if (maildelegate) maildelegate->sortMail(m); } void Manager::signVouchers(Vouchers v) { if (voucherdelegate) voucherdelegate->signVouchers(v); } This concept can be extended to dynamically change the delegated operation. E-mail me if your interested. Delegation (limited) in this fashion reduces code readability and the program structure is moved into run-time structure. It does, however, increase flexibility and can be combined "tastefully" with inheritance. -- Gordon (gordon@meaddata.com)