Design Principles for Collection and Enumerator Interfaces
There are different design principles behind each type of interface:
- A collection interface provides random access to a single item in the collection via the Item method, it lets clients discover how many items are in the collection via the Count property, and often allows clients to add and remove items.
- An enumerator interface provides serial access to multiple items in a collection, it doesn't allow the client to discover how many items are in the collection (until the enumerator stops returning items), and it doesn't provide any way of adding or removing items.
Each type of interface plays a different role in providing access to the elements in a collection.
ATL provides the following classes to help you implement collections and enumerators.
Class | Description |
---|---|
ICollectionOnSTLImpl | Collection interface implementation |
IEnumOnSTLImpl | Enumerator interface implementation (assumes data stored in an STL-compatible container) |
CComEnumImpl | Enumerator interface implementation (assumes data stored in an array) |
CComEnumOnSTL | Enumerator object implementation (uses IEnumOnSTLImpl) |
CComEnum | Enumerator object implementation (uses CComEnumImpl) |
_Copy | Copy policy class |
_CopyInterface | Copy policy class |
CAdapt | Adapter class (hides operator & allowing CComPtr, CComQIPtr, and CComBSTR to be stored in STL containers) |