Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OOP Terminology: "Container" & "Collection"

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

like image 421
Ande Turner Avatar asked Mar 29 '09 09:03

Ande Turner


People also ask

What is a container in OOP?

In computer science, a container is a class or a data structure whose instances are collections of other objects. In other words, they store objects in an organized way that follows specific access rules. The size of the container depends on the number of objects (elements) it contains.

What is a container in programming language?

Containers are packages of software that contain all of the necessary elements to run in any environment. In this way, containers virtualize the operating system and run anywhere, from a private data center to the public cloud or even on a developer's personal laptop.

What is a container in data?

A data container is a data structure that “stores and organizes virtual objects (a virtual object is a self-contained entity that consists of both data and procedures to manipulate the data).” This is similar to the packaging of a meal kit: The vendor ships a consumer a box containing recipes, cooking tips, and the ...

What is containers C++?

A container is an object that stores a collection of objects of a specific type. For example, if we need to store a list of names, we can use a vector . C++ STL provides different types of containers based on our requirements.


2 Answers

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.

like image 176
Alex B Avatar answered Oct 18 '22 11:10

Alex B


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.

like image 38
bayda Avatar answered Oct 18 '22 11:10

bayda