OOP Terminology: “Container” & “Collection”

拈花ヽ惹草 提交于 2020-01-13 09:01:35

问题


Is the C++ term "Container" simply synonymous with the Java term "Collection" ?


回答1:


Yes.

Though, if I may speculate here, C++ term container better emphasizes ownership of contained items, as opposed to Java's collection, where there is no explicit memory ownership (due to garbage collection).

Items in a C++ container are destroyed when a container is destroyed (hence items are contained or owned), in Java items may continue to exist if a collection itself is garbage collected.




回答2:


Container (wikipedia)
Collection (wikipedia)

If I understand correctly - usualy this difference is not significant.

When we talk about group of objects we say "collection of objects".
If we talk about data structure which contain group of objects we say container.

e.g.: std::vector< int > - collection of ints or container vector which contain ints.



来源:https://stackoverflow.com/questions/694387/oop-terminology-container-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!