2 Replies Latest reply on May 27, 2010 7:05 PM by 800387

    Need your opinion

    843853
      Hello all,

      I have a database table which has (name, str) columns. Each "str" row is basically a big string which represent type in C++. I will show one particular string object here.

      {
      version=2;
      $0={
      class="PIScenarioSpace";
      shiftLists_={
      Item0=$1;
      listLen=1;
      };
      };
      $1={
      class="SPCodableList<P<PICAShift>>";
      Item1=$3;
      Item0=$2;
      Item3=$5;
      Item2=$4;
      Item5=$7;
      Item4=$6;
      Item6=$8;
      listLen=7;
      };
      $2={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=-0.2000000000000000111;
      };
      $3={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=-0.10000000000000000555;
      };
      $4={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=-0.050000000000000002776;
      };
      $5={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=0;
      };
      $6={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=0.050000000000000002776;
      };
      $7={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=0.10000000000000000555;
      };
      $8={
      class="PLCAShiftSpotInstrument";
      units_=1;
      instrumentId_=30628;
      amount_=0.2000000000000000111;
      };
      }

      This kind of represents a tree structure where $0 is entry point. $1 is child of $0 (you can see in definition of $0 that it says Item0=$1). Now, I have parsed the whole string and got it into hash table and recursing over it by depth-first-search. I have to store this in my java code in some way (by creating classes) and show this on the screen. The user should be able to modify the amount_ values (the nodes of the tree) and the modified text can also be stored in database. I have almost nailed down database calls, front end etc. But I am kind fo confused about the business layer. Looking at the above string, looks like we need to create PIScenarioSpace, SPCodableList
      and PLCAShiftSpotInstrument
      classes and the inheritance hierarchy should be PIScenarioSpace (root) --> SPCodableList (Level 1) --> PLCAShiftSpotInstrument
      (node). The PIScenarioSpace class will have a List<> of SPCodableList objects and SPCodableList class will have List<> of PLCAShiftSpotInstrument objects.

      What i am confused about is :

      1) Is there a need to create inheritance here. Can't I have just individual 3 classes and then use their objects in List<> the way I want?
      2) Any particular design pattern that I can implement?

      Any thoughts/concerns/improvements/criticism are welcome.

      Thanks.

        • 1. Re: Need your opinion
          jschellSomeoneStoleMyAlias
          That is just a method of creating serialized data. (Myself, especially given 'amount' would find the architecture that lead to this suspect.)

          As a note I suspect strongly that you could create your own serialization code and deserialize this directly into java objects. Not necessarily a good solution but possible. (Actually if you could automate the creation using code generation based on the C++ code then this might even be a good solution.)

          The real problem here is
          1. Identifying all the serialized objects that are currently in use
          2. Dealing with future new serialized objects.

          In terms of a user experience if there are a number of different serialized objects then creating custom UIs for each is probably better.
          In terms of maintenance and stability (both points above) creating a generalized structure and relying on the data itself is going to be easier. If users have been modifying these structures by hand any you are just providing a GUI for that then I would push for that solution.
          Is there a need to create inheritance here
          There is absolutely no inheritence in what you posted.
          • 2. Re: Need your opinion
            800387
            Why not use an existing lightweight serialization protocol such as JSON, where both C++ and Java have libraries to serialize and deserialize without issue? Why your own protocol?

            - Saish