Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Yet another inheritance vs containment question



henrik wrote:

> On a more general note, let's say we have
> 
> class A: private B, public C
> {
>    // ctor
>    A(param 1, param 2) : B(param 1, param 2), C(method from B, ...)
> {...}
>    ...
> }
> 
> where "method from B" returns a value that depends on param 1 and
> param 2. This might all be just theoretical (all though I think not,
> the code at the top is almost such a construct). Does anyone have some
> thoughts on a design like this? Does anyone have some real life code
> examples that illustrates this construct in practice?

Most of the time, we use IS_A to denote an inheritance relationship, HAS_A
for a containment relationship, and in this case, the relationship between
A and B is denoted by USES_FOR_IMPLEMENTATION. Doing it this way is
convenenient when implementing the class because there is no need to create
a data member and you do not need constructs as:

        B b;
        ....
        b.doThis();
        b.doThat();

to make it work. The simple

        doThis();
        doThat();

will suffice (provided that C does not have them also).

-- 
Ruurd
.o.
..o
ooo

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.