The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Typeless Data in C++?

I've been handed a C++ codebase that, among other things, abuses inheritance in a way that would horrify even the most seasoned programmer.

Nice Intro, eh?  :)

I'm considering refactoring this codebase by pulling both the frontend and the backend out of it (layered software, whodathunkit).  I'm contemplating creating a data type that carries typeless data to shuttle information between the layers (middle to front, back to middle).  An example would be a GUI list, I can hand it one of these data types that would have the information needed (the front-end would most likely have required data, and then optional data).

In my head I'm seeing this as a hash-like structure, similar to a Ruby Hash and most likely implemented as a std::list or map.  It would most likely use key/value pairs that were string/data node, the data node would have facilities for converting to the intrinsic data types, et al (this would be for strictly flat, intrinsic data types.  It would not be used to serialize objects or pointers).

I can see the pros/cons of such an approach, but I thought I'd get opinions from others to see what they thought of such an approach.
Friday, July 13, 2007
It appears from your post that you are going for a three tiered approach, though it's not clear what you mean by front-end and back-end and what you plan to leave in the middle. Also, there is a difference between refactoring and building from scratch. There is just so much architectural change that you can apply while retaining the majority of the existing code. If you are indeed aiming for a three layered approach, and are willing to implement lots of changes, look at one of these design patterns: MVC (, MVP, and Presenter First ( If your intent is two levels you may want to take a look at the Mediator pattern (

Regarding the Typeless Data - it's difficult to say without more detailed information, but in principle I'm not in favor. C++ is a statically typed language and you appear to be trying to go against the grain of the language. This sort of a decoupling is more appropriate between services, not inside an application. Still, if you are looking for some sort of generic data type check out Boost any and variant:
Dan Shappir Send private email
Friday, July 13, 2007
yes, use a map, I've seen this approach and it is a great way to dynamically evolve the system without wasting a lot of time synching the interface points.
Friday, July 13, 2007
1 yay and 1 nay.  I need a 3rd opinion (kidding).

I use the term Refactor very loosely.

The system is built on top of an old record DB system (pre relational) and they've inquired about moving it to SQL Server.  The problem is that they use MFC for the frontend and the've adopted MFC's practice of using inheritance to extend functionality.  The end result is that you have business objects that inherit directly from the data objects that are used to retrieve/update data.  On top of that, the abstractions they've used are all wrong (I'm told it was developed by a heating and air guy turned self-taught programmer).

So when I say frontend/backend what I really mean is pull MFC out of the application and place it on top, and to pull the data retrieval/update out of the application and put it on bottom (a thin layer dedicated to nothing but CRUD).  That hoary mess in the middle will be the application, not necessarily the "middle tier".

Ultimately what I'd like to do (and feel free to offer critiques/suggestions) is to use wxWidgets for the DB access and I'd *like* to replace the MFC frontend with wxWidgets as well if for no other reason than preference, and keeping to a single framework.  I have no experience with wxWidgets DB stuff, so anyone with experience do tell :)

The reasoning for the "typeless data" is that it would allow me to shuttle information in a way that is both uniform and flexible.
Saturday, July 14, 2007
Check if the library that you're using already has typeless data.  For example, in Qt it's called QVariant.  Use it sparingly.  Strong typing is there for a reason.
Jeff Zanooda Send private email
Saturday, July 14, 2007
bahen Send private email
Sunday, July 15, 2007
Unfortunately boost::any and the various variant data types are not what I'm looking for.
Sunday, July 22, 2007
consider a rewrite and use c#, .net,, and windows forms. seriously. I love c++, I really do. but if you're doing a data centric app on windows, and you have some kind of choice in the matter, i don't know why on God's green earth you would use c++. at least evaluate the possibility. microsoft has done a GREAT job (i think) on the windows forms dev environment, and certainly they've come a very long way from mfc. i think you'll be surprised at how much crappy mfc code just drops away.
Tuesday, July 31, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz