Is there a better design / design method?

I have currently completed one of two phases of a project that requires me to write database information in XML using C ++. Although the use of a third-party tool was used to actually format XML tags and data, I still had to develop a model along with business logic to accept database tables and map them to XML structures.

To do this, I created an individual class for each XML structure, which led to a large number of classes (~ 75). Each class knew how to read the table associated with it and serialize itself in XML through a third-party tool. As a result, the system worked very well (in terms of time and budget), and output errors were very easy to find.

The second phase is almost identical, but instead of formatted text, it will be binary data. Therefore, although I am still considering using the same strategy as in the first phase, I would like to know if there is a better design method or template that can succumb to this problem? In particular, due to the large number of dependencies in some XML classes, unit testing was very difficult at the first stage.

+4
source share
3 answers

Another idea that may also be relevant:

If performance is not an issue, shared data containers can also be used. A common data container can take the specification of a single node (for example, an XML node or object, or even records in a table) and simply store such a container.

Thus, 75 classes can be replaced by one or more. Services such as serialization can also be provided in general.

Thus, different instances can play the role that different classes still play.

As I understand it, the data primitives used are pretty straightforward and limited. Thus, it can be implemented quite simply.

+1
source

You are describing a classic Visitor application. You need to go through your object model for two purposes, output XML once, other binary time data. This is well explained in a group of four books .

Each element of your model must accept a visitor of a recognized type (usually IVisitor ), and then call a method, usually called AcceptVisitor for that visitor. This is a method that converts an object to XML, binary data, print format, or something else. Then he can also direct the visitor to child objects and so on. Then you write an XmlVisitor that implements IVisitor and "visits" your structure with it - the result is XML. Similary, you can β€œvisit” using BinaryVisitor and get your binary output.

+7
source

Build a generator - if possible - automates the generation of classes.

The generator, of course, can be loaded with a specification language that indicates how the data is stored in the database.

This involves thinking about how data can be stored as evenly as possible.

Even better (in terms of developmental effectiveness - not in terms of teaching / learning template): use a generator that already exists (Open Source or Commercial).

Edit: There are several libraries / frameworks that should perform just such tasks. You are still using the library as far as I read, but it looks like it does little. There are layers / structures for storing OO data from / to datase. XML data is nothing more than an object-oriented representation. You may be writing a layer to achieve the full goal, but using a third-party product may be useful (in many cases).

+2
source

All Articles