[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Parent - Child

Posted on 2009-03-30
3
Medium Priority
?
337 Views
Last Modified: 2012-05-06
Hello,

I have a class called "Template" and one more class called "TemplateCollections" (This is just a collection Template classes)

I will be serializing the TemplateCollections class and sending to a different .net application, where they will be deserializing the object back.

When I add Template class to TemplateCollections, I would like to maintain a parent-child relation between the classes.

For e.g I have 4 Template classes - Template1, Template2, Template3, Template4
where
Template2 is child of Template1
Template3 is child of Template2
Template4 is child of Template1

What is the optimized way of achieving this, considering the serialization process?



0
Comment
Question by:praveenuni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 24026831
hi ,

I had given a code snippet which defines the template class , the template class has two properties
 
  1. Template Name
  2. TemplateCollection

Template template1 = New Template();

( TemplateCollection  can have list of templates -> from ur example we can have "template2" and "Template4" in this collection )
 
  So template1 will have two child templates --> "template2" and "template4"

  from ur example "template3" should be child of "template2" that should also be possible.
 
  It will hold good for serialization also as we have the collection class.
 
  I am not sure whether you are looking for something like the above one.

 hope it helps

 Thanks,
 Nanda
 
[Serializable]
public class Template
{
    private string _templateName;
    private Template _childTemplateObj;
 
    public string TemplateName
    {
        get
        {
            return _templateName;
        }
        set
        {
           _templateName = value;
        }
    }
 
    // This is of type "Template" class this can hold template 
    public TemplateCollection ChildTemplateList
    {
        get
        {
            return _childTemplateObj;
        }
        set
        {
            _childTemplateObj = value;
        }
    }
}
 
// This holds the list of "Template" class
public class templateCollection
{   
}

Open in new window

0
 

Author Comment

by:praveenuni
ID: 24027770
Thanks Nanda. Since we are doing serilization, the size of the final object will be increase a lot. Is there a way we can define parent for every object instead of defining the children?
0
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 2000 total points
ID: 24028262
Praveenuni ,

you need to decide during serialization what do you want to serialize in the sense do you want to serialize only the parent object or the whole object.

I can suggest two solutions

solution 1:

If you need to reduce the size of the object after serialization probably use "XmlIgnoreAttribute" (something like this) to block the unwanted attributes from serialization.

solution 2:

To define parent for every object , have two more properties named Template_Id and Parent_template_Id so that the template can be identified uniquely , following points need to be taken care

   1. The template_id needs to be assigned a unique value while creating an object
   2. The Parent_template_id needs to assigned null if it is the parent element or else this should hold the parent Template_Id
   3. For generating unique Id probably you can use GUID or you can use your own logic and can have a data structure which holds the parent child relationship
 
Hope the state will be maintained for all these actions

Hope this helps

Thanks,
Nanda
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question