|
Re: Separation of Concerns
|
Posted: Nov 2, 2005 8:13 PM
|
|
> One of the design problems with the STL, is that the > containers have multiple responsibilities.
I don't see any design problem (yet); the STL containers seem to conform to their original design and intentions. There's a difference between a design problem and something you don't like or agree with.
> In the STL the containers are actually factory classes.
I don't follow: STL containers don't create instances of the objects they contain, so how are they factories? If you mean the templates that create the STL containers are analogous to factory classes, OK, though it's more usual to refer to the template mechanism as blueprints (or templates) and to the instantiations as specializations. If you're using novel terminology you need to explain.
> (ADT, e.g. stack, list, array, deque). For instance: you > might think that you could create a reference to an object > within an STL container, but unfortunately the object can > be easily moved invalidating your reference silently.
I wouldn't think I could create a reference to an object inside an STL container without regard to the rules and idioms. Iterators, for example, are invalidated in well-defined circumstances; nothing silently moves things around invalidating references unless your code initiates the move. Whenever I've seen code that has to care about whether a reference to something inside a container, or an iterator, is good that has happened because the container was too widely accessible (not scoped) or not encapsulated appropriately. I don't consider misuse of STL containers or iterators a design problem.
> This kind of behaviour is frustrating at first, but > logical when you consider that an STL collection > has to grow/shrink to accomodate insertion/deletion.
That is the documented behavior of the containers, not something programmers should discover by trial and error after much frustration.
> In order to deal with this I apply the principle of > <i>separation of concerns</i>: I create separate classes > for my objects: an object lifetime manager, and an ADT. > Usually the object manager is implemented as a linked list > of arrays. I then create the appropriate ADT (e.g. tree, > linked list, heap) which my algorithms operate on. > > Do you have other examples of problems which are solved > through application of the principle of separation of > concerns?
I don't understand what you're talking about. Do you have anexample of an STL problem and your proposed solution?
|
|