Re: design question - member function argument or pointer member

From: Keith H Duggar (demicheme_at_aol.com)
Date: 01/26/04


Date: 26 Jan 2004 17:20:27 GMT

So far all of the postings have focused on inheritance, composition, etc.
However, in your original question you stated :

> object of class A needs for example for the
> operator() and object of class B

Allow me to paraphrase your statement :

    A::somefunction() requires and object of class B

In that case why not follow your own suggestion of :

A::somefunction ( B const & b ) { ... }

This is what the argument list of a function are for, to supply the arguments a
function needs to carry out its work. This seems to solve all of the problems
you have outline. Namely :

1) A::somefunction is guaranteed to have an available B or it could not have
been called.

2) If other class functions require the same instance of B then simply pass
that instance to them as well :

    C::somefunction ( B const & b ) { ... }
    D::somefunction ( B const & b ) { ... }
    etc ...

This method also has many other advantages :

1) class are not required to hold pointers or references to objects they may or
may not use. (After all, what guarantee do we have that the client will even
call somefunction.) This falls under the "only pay for what you use" paradigm
with C++ supports very well.

2) you can run A::somefunction multiple times with different B objects with a
single function call.

3) you can run A::somefunction, B::somefunction, ... , X::somefunction with
different B objects at your discretion.

In essence, this exactly what functions are designed to do: take arguments and
do work using them.



Relevant Pages

  • Re: Generics in Lisp?
    ... With the caveat that: ... it does NOT guarantee that the ...
    (comp.lang.lisp)
  • Re: ORDER BY and IDENTITY
    ... directed toward a response to the original question, ... > The order by clause must work, is it the sequence of the identity values ... >> SQL Server does guarantee the order of the result set based on the ORDER ... >> direction used to create the clustered index. ...
    (microsoft.public.sqlserver.programming)
  • Re: Aggregation vs composition
    ... > "guarantee that we can ignore the contained objects at some high level ... A composition don't express that it's parts can be ignored but it tells ... You may use the facade design pattern to "hide" associated objects. ...
    (comp.object)
  • Re: dynamic type checking - a pauline conversion?
    ... >> guarantee that any are related by inheritance, ... > guarentee is with an abstract class: ... That's the most explicite and possibly even most save way to guarantee it. ... Take care, Ilja ...
    (comp.object)
  • Re: Looking for a simple function with known values
    ... William Elliot wrote: ... In answer to the original question: ... There is nothing to guarantee that such an interpolating cubic has ... to be an increasing function, but in this case it is. ...
    (sci.math)