Re: How to access a C++ class object from the aggregated interface-class

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Naanthaa N (naanthaan2k_at_yahoo.com)
Date: 03/16/04


Date: Tue, 16 Mar 2004 02:41:08 -0800

Hi,
>From the FAQ 7, It looks like that we can use templates in the CSinkAgg to access the variables (i.e., CSrcObj instance) in the CSinkObj class. i,e., by passing CSinkObj as a template argument to CSinkAgg and there we can accesss CSrcObj instance. Apart from the 'code bloat', this technique could be useful. Is my understaning correct?
-Naanthaa N
     
     ----- Alexander Nickolov wrote: -----
     
     To finish what Igor started, some techniques for source code reuse
     with ATL COM objects are detailed in these two FAQ articles:
     
     http://www.mvps.org/vcfaq/com/7.htm
     http://www.mvps.org/vcfaq/com/8.htm
     
     --
     =====================================
     Alexander Nickolov
     Microsoft MVP [VC], MCSD
     email: agnickolov@mvps.org
     MVP VC FAQ: http://www.mvps.org/vcfaq
     =====================================
     
     "Igor Tandetnik" <itandetnik@mvps.org> wrote in message news:ejoCh3rCEHA.4080@TK2MSFTNGP09.phx.gbl...
> "Naanthaa N" <naanthaan2k@yahoo.com> wrote in message
> news:B8E75A60-BB25-4543-B79E-2C933997E966@microsoft.com...
>> Hello there,
>> I have a class called CSinkAgg -associated with
> ISinkAgg. This class is being aggregated into CSinkObj, i.e., I am
> creating the instance of ISinkAgg at CSinkObj::FinalConstruct. Now, I
> have an instance of another class, called CSrcObj at CSinkObject. How
> do i access CSrcObj's instance from CSinkAgg? Pls do help me!
>> You don't. Aggregation is a technique for binary reuse, not for source
> level reuse. With aggregation, you don't have C++ classes - you have COM
> components that expose interfaces.
>> So, you can make CSrcObj a COM object and have it implement an interface
> you define, say ISrcObj. CSinkAgg can also implement an interface that
> has a method that accepts ISrcObj* as a parameter. CSinkObj will call
> this method right after creating CSinkAgg.
>> But before you do all this, reconsider the wisdom of using aggregation
> in the first place. Again, aggregation is appropriate when you want to
> reuse a component for which you don't have the source code or which you
> want to isolate in a separate module for some reason. It appears that
> you have source for all three components, and all three are implemented
> in the same module. In this case, regular C++ reuse techniques are much
> easier and more flexible.
> --
> With best wishes,
> Igor Tandetnik
>> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken
>>



Relevant Pages

  • Re: How to access a C++ class object from the aggregated interface-class
    ... some techniques for source code reuse ... With aggregation, you don't have C++ classes - you have COM ...
    (microsoft.public.vc.atl)
  • Fwd: Re: NT/W2K Source leak
    ... Top security experts. ... Cutting edge tools, techniques and information. ... patches to Microsoft like other open source projects:). ... source code audits - if they haven't been audited already. ...
    (Bugtraq)
  • Re: Open source quiry
    ... variant of rt FreeBSD. ... The FreeBSD license allows reuse of the source code. ...
    (freebsd-questions)
  • Re: BigDecimal API docs andd "reuse"
    ... based on a new BigInteger. ... This allows to use reuse the same object without the danger of getting it changed silently behind your back by an other part of your code. ... So valueOfcould cache previously generated BigDecimals, and when you ask for a BigDecimal with the same value, it could give you the previously cached object, not a new one. ... You would have to study the source code to figure it out. ...
    (comp.lang.java.programmer)
  • Re: Hints to using Linux sources to answer your own questions
    ... > why something is happening by looking at the source code. ... > looking, what techniques to use? ... > linux is hitting my floppy disk when I switch off my monitor ... > with built-in USB hub. ...
    (comp.os.linux.misc)