Feeds

The database abstraction framework strikes back

Part 2: C++ Generic Coding

Build a business case: developing custom apps

In my last article, I looked at one of the differences between the C++ and Java communities; the availability of application development frameworks that have a profound effect on programmer productivity. I mentioned specifically the Java example of Hibernate and tried to identify reasons why the Java community is more innovative with this type of code reuse.

The resulting comments were interesting; particularly the point of the different histories of the two languages. C++ has evolved from C to add object oriented and later generic paradigms, the goal was always to allow exploitation of new modelling techniques and not to find patterns in application development that could be exploited. It could be argued that the contrary applies to Java. Additionally, as the Java syntax is more limited, there are less ways to solve any given problem. Consequently, there is more commonality in solutions to problem classes with Java and, as a result, the process of factorising is easier.

Some people make the point that both Java and C++ have their place and for any given problem, your choice is based on which is more appropriate to the constraints you're operating under. This is true; however, there are a wide range of problems where there isn't a fundamental driver forcing one choice over the other; for example, in web servers Java wins out because of the frameworks that exist to support the application developer. How has Java colonised this space so effectively? If the same frameworks existed in C++ then wouldn't C++ be an equally effective technology choice? As a C++ developer and enthusiast, I don't want to give up this ground so easily!

Finally, there's the argument that it simply isn't possible to implement a tool such as Hibernate without language support such as Reflection. This is where the rest of this article comes in; let's see if we can find a design for such a tool in C++. I think the ideas transform pretty naturally and we can leverage the support in C++ for generic programming to compensate for the absence of Reflection. In fact, just to prove the point I implemented a version and the source is available on SourceForge.net here if anyone wants to play with it...

Hibernate, sort-of, for C++

So, starting from scratch, what's needed to provide an abstraction layer that presents an object oriented interface to a relational data model? Well, we already know this is possible as Hibernate does it for Java, so it's simply a question of providing these capabilities in C++. However, I'm not going to assume prior knowledge of Hibernate and for the sake of respectability, I'm not going to copy blindly what those good people have done before us.

To aid the discussion, Entity Relationship vocabulary is used when referring to the relational domain and Object Oriented vocabulary to refer to the C++ interface we want to provide. I'm also going to work with the simple and classic example of a salesperson and his/her customers. In this relational data model, I have two entities, the salesperson and the customer, and there is a one-to-many relationship that associates one salesperson to his/her many customers (see Figure 1).

Figure 1: Diagram showing the Entity-Relationship Model for customer and salesperson.

So what would a reasonable object-oriented view of this data be? Well, we can imagine that there will be an object representing each entity, one each for salesperson and customer. A second question is more difficult, how do we manage the relationships? We want to be able to ask a salesperson object "who are your customers?" even though in the relational model the question is more "which customers are associated with some salesman"?

Gartner critical capabilities for enterprise endpoint backup

More from The Register

next story
'Stop dissing Google or quit': OK, I quit, says Code Club co-founder
And now a message from our sponsors: 'STFU or else'
Why has the web gone to hell? Market chaos and HUMAN NATURE
Tim Berners-Lee isn't happy, but we should be
Microsoft boots 1,500 dodgy apps from the Windows Store
DEVELOPERS! DEVELOPERS! DEVELOPERS! Naughty, misleading developers!
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Uber, Lyft and cutting corners: The true face of the Sharing Economy
Casual labour and tired ideas = not really web-tastic
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
prev story

Whitepapers

Top 10 endpoint backup mistakes
Avoid the ten endpoint backup mistakes to ensure that your critical corporate data is protected and end user productivity is improved.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Backing up distributed data
Eliminating the redundant use of bandwidth and storage capacity and application consolidation in the modern data center.
The essential guide to IT transformation
ServiceNow discusses three IT transformations that can help CIOs automate IT services to transform IT and the enterprise
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.