The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Separation of Concerns
by Christopher Diggins
November 2, 2005
A very important programming principle is that of separation of concerns. A class should have one clearly defined responsibility. When this is violated problems arise, for instance in the STL.


One of the design problems with the STL, is that the containers have multiple responsibilities . Understanding the STL limitations can allow you to more effectively use it, and become a better coder.

In the STL the containers are actually factory classes. They manage object lifespans,and memory allocation. This makes them behave rather strangely as abstract data types (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. 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.

In order to deal with this I apply the principle of separation of concerns: 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. To quote David Wheeler out of context:

"Any problem in computer science can be solved with another layer of indirection."

Do you have other examples of problems which are solved through application of the principle of separation of concerns?

Talk Back!

Have an opinion? Readers have already posted 17 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use