mardi 5 avril 2016

When elements call methods of the container object, what is this called and is it bad practice?

To illustrate what I mean, I will give an example.

There is a memory management class that allocates and manages memory of objects I have in my example. It has a pointer to a big block of heap and it arranges objects on the block as it sees fit. Naturally, it is a container, and the objects allocated on it's block of memory are elements. I have an instance of a dynamically sized class like an std::vector. When I call .add() on this instance, it just grew in size, thus needs to be reallocated. It needs to call the memory manager to reallocate it self, because it just grew in size.

It appears unavoidable in certain situations like above. I'm wondering if this is good design in general or bad, and if it has a name.

Aucun commentaire:

Enregistrer un commentaire