书上说:
TComObject有三个构造,这意味着要创建COM对象的实例可以有3种方式。一是Create(),用于实例化一个简单的COM对象,所创建的实例不是聚合的一部分。二是CreateAggregated(),用于实例化一个简单的COM对象,所创建的实例成为聚合的一部分。三是CreateFromFactory()用于实例化一个简单的COM对象。与Create不同的是,CreateFromFactory()在创建实例的同时还对实例进行初始化。什么叫“使实例成为聚合的一部分”?我查了书,却没有找到“聚合”的解释?

解决方案 »

  1.   

    TComObject is a COM object that supports the IUnknown and ISupportErrorInfo interfaces. TComObject provides the implementation for simple COM objects that have:A class identifier (CLSID) for external instantiation using a class factory.
    Optional support for aggregation implemented through the IUnknown methods.
    Support for the SafeCall calling convention and OLE exception-handling by implementing IProvideErrorInfo.
    Support for the the IErrorInfo mechanism.TComObject can be used as a base class for creating classes for COM objects that must have a class identifier (CLSID). CLSIDs are used to register the class in the database registry and to externally instantiate the class using a class factory. The class factory for TComObject is TComObjectFactory. The class factory properties provide information about TComObject class, such as its name, description, CLSID, and so on. The TComObjectFactory methods are used to register the TComObject class in the registry and to instantiate it. TComObject can be instantiated either as a single COM object, or as part of an aggregate. The IUnknown methods are implemented in TComObject to support aggregation by appropriately delegating to the controlling IUnknown interface when the instantiated COM object is the inner object of an aggregate. Consequently, for all interfaces that are implemented by the inner COM object, its reference count will not be directly affected when an interface reference is created.TComObject supports the ISupportErrorInfo interface which allows OLE Automation controllers to query whether an error object will be available, and ensures that error information can be propagated correctly up the call chain. By implementing the ISupportErrorInfo interface method, InterfaceSupportsErrorInfo, TComObject supports the IErrorInfo mechanism, thereby providing support for OLE exception-handling and the safecall calling convention. The information available through the IErrorInfo interface is used for SafeCall error handling.Using TComObject will not require the instantiated object to have a type library.Implemented methods of ISupportErrorInfoInterfaceSupportsErrorInfo method
      

  2.   

    聚合:不能拆开。  你与你的手。
    组成:可以拆开。  计算机与显示器。看下 UML ,肯定很多。
      

  3.   

    UML中的确有“聚合”这个词汇,但是我读不懂是什么意思。
      

  4.   

    聚合(Aggregation)聚合(图F)是关联的一种形式,代表两个类之间的整体/局部关系。聚合暗示着整体在概念上处于比局部更高的一个级别,而关联暗示两个类在概念上位于相同的级别。聚合也转换成Java中的一个实例作用域变量。
    关联和聚合的区别纯粹是概念上的,而且严格反映在语义上。聚合还暗示着实例图中不存在回路。换言之,只能是一种单向关系。示例代码:
    public class Employee{
    private EmpType et;
    public EmpType getEmpType(){
    ……
    }
    }Employee和EmpType是聚合关系。
    ====================================
    但是!!!!!!!!!!!!!!!
    “TComObject有三个构造,这意味着要创建COM对象的实例可以有3种方式。一是Create(),用于实例化一个简单的COM对象,所创建的实例不是聚合的一部分。二是CreateAggregated(),用于实例化一个简单的COM对象,所创建的实例成为聚合的一部分。”
    还是不能解释这段话是什么意思。