473,378 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Design to add two composite object

I have a Composite object (written in C++) which represents a XML tree. I need to design for adding/merging two composite objects.

To make it more clear, I have following two XML tree which represents the same object class:

Object #1:
-----------
Module M1
SubModule S1
Routine R1
Routine R2
SubModule S2
SubModule S3

Object #2:
-----------
Module M1
SubModule S1
Routine R1
SubModule S2
Routine R3
SubModule S4



A) First problem is to represent above XML tree in C++ class hierarchy

B) Second problem is to add/overlay first object with second object as follows:
a) Add (object1.Add(object2):
It means add only the extra components and leave rest of the existing
objects untouched. That means in the above case i) add "Routine R3" of
Object2 to SubModule S2 of Object1 ii) add "SubModule S4" of Object2 to
Object1
b) Overlay (object1.Overlay(object2):
In case of overlay, it means that add as well as update the existing objects.


Thanks
Devendra
Sep 13 '07 #1
5 2180
Reposting XML trees:

Expand|Select|Wrap|Line Numbers
  1. Object #1:
  2. ---------------
  3. <Module Name="M1">
  4.   <SubModule Name="S1">
  5.     <Routine Name="R1>
  6.     </Routine>
  7.     <Routine Name="R2>
  8.     </Routine>
  9.   </SubModule>
  10.   <SubModule Name="S2">
  11.   </SubModule>
  12.   <SubModule Name="S3">
  13.   </SubModule>
  14. </Module>
  15.  
  16. Object #2:
  17. ---------------
  18. <Module Name="M1">
  19.   <SubModule Name="S1">
  20.     <Routine Name="R1>
  21.     </Routine>
  22.   </SubModule>
  23.   <SubModule Name="S2">
  24.     <Routine Name="R2>
  25.     </Routine>
  26.   </SubModule>
  27.   <SubModule Name="S4">
  28.   </SubModule>
  29. </Module>
  30.  
Sep 14 '07 #2
sicarie
4,677 Expert Mod 4TB
So where are you stuck? What do you need help on?
Sep 14 '07 #3
A) First problem is to represent above XML tree in C++ class hierarchy

B) Second problem is to add/overlay first object with second object as follows:
a) Add (object1.Add(object2):
It means add only the extra components and leave rest of the existing
objects untouched. That means in the above case i) add "Routine R3" of
Object2 to SubModule S2 of Object1 ii) add "SubModule S4" of Object2 to
Object1
b) Overlay (object1.Overlay(object2):
In case of overlay, it means that add as well as update the existing objects.



This is a very generic problem and I think there must be some elegant solution for it. If anyone have link for it please help.
Sep 20 '07 #4
sicarie
4,677 Expert Mod 4TB
So, as per our Posting Guidelines, what have you tried already?
Sep 20 '07 #5
I see following picture of class structure:
-------------ProgramObject
----------------- |-----------------
|-----------------|----------------- |
Module SuModule Routine

Expand|Select|Wrap|Line Numbers
  1.  
  2. Important things to note
  3. 1) ProgramObject will be a composite object and represent a general tree structure 
  4.  
  5. 2) Additions in class ProgramObject :
  6.  
  7. Class ProgramObject
  8. {
  9.    List<ProgramObject  *> m_MyChilds;
  10.    Enum ProgramObjectType
  11.    {
  12.       Module,
  13.       SubModule,
  14.       Routine
  15.    }
  16.    Virtual ObjectType  GetType() = 0;
  17.    Virtual string GetName() = 0;
  18.    Virtual void AddValue(ProgramObject *pobject) = 0;
  19.     Virtual void Add(ProgramObject * pTarget);
  20. };
  21.  
  22. Class Module
  23. {
  24.       virtual ObjectType  GetType() { return Module};
  25.       void AddValue(Module *pobject)
  26.       {
  27.                   ……………………….
  28.                   Do needful for adding two Realms
  29.                   ……………………….
  30.       }
  31. }
  32.  
  33. 3. Implementing Add():
  34.  
  35. ProgramObject::Add(ProgramObject * pTarget)
  36. {
  37.    If(GetType() == pTarget->GetType() && GetName() == pTarget->GetName())
  38.    {
  39.       AddValue(pTarget);
  40.    }
  41.    for( each child1 in list m_MyChilds )
  42.    {
  43.       for( each child2 in list pTarget->m_MyChilds )
  44.       {
  45.          child1->Add(child2);
  46.       }
  47.    }
  48. }
  49. }
  50.  
  51.  
Here I have two concerns with this approach
c)ProgramObject::Add(ProgramObject * pTarget) do extra iterations --------- trying to call Add() for each possible child pair of two trees
b)Calling GetType() --- Not a good approach to ask some class about itself …. One should use polymorphism instead.
Sep 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pelle Beckman | last post by:
whew. This must be my tenth post or so just this week - thank you to everyone who took the time to answer my questions! Now, I'm helping a friend with an OpenGL application and we need some...
3
by: Merlin | last post by:
Design Problem =============== Would appreciate any help or suggestion on this design issue. I have spent a great deal of time and effort for an elegant solution but it seems I am not getting...
11
by: FluffyCat | last post by:
In Febraury - April of 2002 I put together in Java examples of all 23 of the classic "Gang Of Four" design patterns for my website. Partly I wanted to get a better understanding of those patterns....
1
by: Takayasu Kenduma | last post by:
hi everybody. i am quite new about design patterns and i would like improve my experience in c# applications design. so i choose a common problem as a draft to talk about in the group to find the...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
14
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or...
54
by: csolomon | last post by:
Hello: I was wondering if I could get some input on how to address a design issue, involving my composite table. I have one portion of my project complete. The following forms and reports I...
0
by: jsimone | last post by:
This question is about DB2 table design and performance. We are using DB2 UDB Enterprise 8.2 on Linux. We have 6 tables in a parent-child (one-to-many) relationship with each other. Each...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.