Restrict type in a Collection inside a class module

后端 未结 4 1536
暖寄归人
暖寄归人 2020-12-16 06:36

I have a collection inside a class module. I\'d like to restrict the object type that is \"addable\" to this collection, i.e. collection should only ever accept objects of o

4条回答
  •  误落风尘
    2020-12-16 06:59

    Yes. The solution is to make your collection private and then make public wrapper functions to add, remove, getitem and count etc.

    It may seem like hassle to write the additional code but it is a more robust solution to encapsulate the collection like this.

提交回复
热议问题