com学习笔记(7)包容与聚合

前端之家收集整理的这篇文章主要介绍了com学习笔记(7)包容与聚合前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@一.包容

如同适配器,调用方法时,调用内部接口方法,对其内部接口进行了封装

// Interface IY
virtual void __stdcall Fy() { m_pIY->Fy() ;} //@N
@H_301_0@二.聚合

特殊的包容形式,把内部的接口指针直接暴露给外部

HRESULT __stdcall CA::QueryInterface(const IID& iid,void** ppv)
{     
    if (iid == IID_IUnknown)
    {
        *ppv = static_cast<IUnknown*>(this) ; 
    }
    else if (iid == IID_IX)
    {
        *ppv = static_cast<IX*>(this) ;
    }
    else if (iid == IID_IY)
    {
        trace("Return inner component's IY interface.") ;
#if 1
        // You can query for the interface.
       return m_pUnknownInner->QueryInterface(iid,ppv) ; //@N
#else
        // Or you can return a cached pointer.
        *ppv = m_pIY ;   //@N
        // Fall through so it will get AddRef'ed
#endif
    }
    else
    {
        *ppv = NULL ;
        return E_NOINTERFACE ;
    }
    reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
    return S_OK ;
}

http://www.yesky.com/74/1754074.shtml

包容

http://www.cnblogs.com/shipfi/archive/2007/02/15/651294.html

http://blog.csdn.net/insidekernel/archive/2008/03/11/2169599.aspx

原文链接:https://www.f2er.com/javaschema/287802.html

猜你在找的设计模式相关文章