Design Principles for Collection and Enumerator Interfaces

330 篇文章 ¥19.90 ¥99.00
集合接口通过Item方法提供随机访问,Count属性显示元素数量,并允许添加和删除元素。而枚举器接口提供序列访问,不提供元素数量信息,也不支持添加或移除元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
ClassDescription
ICollectionOnSTLImplCollection interface implementation
IEnumOnSTLImplEnumerator interface implementation (assumes data stored in an STL-compatible container)
CComEnumImplEnumerator interface implementation (assumes data stored in an array)
CComEnumOnSTLEnumerator object implementation (uses IEnumOnSTLImpl)
CComEnumEnumerator object implementation (uses CComEnumImpl)
_CopyCopy policy class
_CopyInterfaceCopy policy class
CAdaptAdapter class (hides operator & allowing CComPtr, CComQIPtr, and CComBSTR to be stored in STL containers)
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值