一.包容
如同适配器,调用方法时,调用内部接口方法,对其内部接口进行了封装
// Interface IY virtual void __stdcall Fy() { m_pIY->Fy() ;} //@N
二.聚合
特殊的包容形式,把内部的接口指针直接暴露给外部
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