Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:51:22+00:00 2026-05-26T06:51:22+00:00

In my current project, I have quite a few objects I need to persist

  • 0

In my current project, I have quite a few objects I need to persist to XML and inflate at runtime. I’ve been managing this through .NET’s DataContracts. What I am doing right now is creating a separate class that represents the objects I’m serializing and reading/writing those to/from disc to avoid having too much responsibility in a single class. Here’s an example:

public class Range
{
    private float _min;
    private float _max;

    public float Min { get { return this._min; } }
    public float Max { get { return this._max; } }

    // Constructrs & Methods...

    public SerializedRange GetAsSerializable();
}

The Range class has the complimentary class:

[DataContract]
public class SerializedRange
{
    [DataMember]
    public float Min;

    [DataMember]
    public float Max;

    // Constructor...
}

My question then is, who should be responsible for actually taking the Serialized version of the object and inflating it into the actual object? I see three options, but I’m not sure which (if any of them) would be the best:

  1. Give the Serialized version of the object an instance method that spits out an inflated instance, using the available constructors/factories of the sister class.
  2. Give the sister class a factory that takes an instance of the serialized version to construct itself.
  3. Don’t have either the class or it’s Serializable counterpart do anything- have the code that reads in the Serialized objects manually create the regular objects using whatever constructors/factories they’d regularly have.

I realize that in certain situations you’d have to do it one way or the other because of constraints outside of this somewhat contrived example. Since there’s more then one way to do it though, what I’m really looking for is a general rule of thumb that yields neat, readable, and expandable code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:51:22+00:00Added an answer on May 26, 2026 at 6:51 am

    If you ‘break’ you application into constituent parts what logical components would you get? Here are few based on my understanding:

    1. Domain Objects (Data that you are storing)
    2. Data Layer – responsible for persisting the data (and retrieving it)

    and many others (but just taken a subset as per your description)

    Now, the job of the data layer is to write the content out to some storage – XML files to disk in your case.

    Now, when you ‘query’ the file who fetches it? The data layer. Who ‘should’ populate the corresponding domain object? Well the data layer itself.

    Should the data layer ‘delegate’ the responsibility of population to a separate class/factory? It depends if it’s ever going to be reused by someone else. If not, concepts like inner classes can be of good help (they exist in the java world, not sure of it’s equivalent in C#.NET). That way you’ll have it modularized into a specific class, which is not publicly visible to other classes, unless you want it that way.

    Should you go with factory? Yes, you may. But make sure it’s logically correct to do so. You could land up with many object inflators – that could isolate the inflation functionality to one class and the factory could itself be a part of the data layer (if you want it that way).

    Once you delineate the concerns you’ll be in a better position to decided where to put that piece of code. I’ve provided some pointers that could come in handy.

    Hope it helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to automate quite a lot in my current project. For this, I
I have a few classes in my current project where validation of Email/Website addresses
I am using LINQ2SQL in my current project. I have a quite a lot
I have been struggling with this for quite a while, and my adventures with
I want to use the current version of bundler (there have been quite some
In my current project I have data about colors. Each color is either a
In my current project we have a large repository of content that was originally
I have a requirement on my current project (a Flex app which will be
I have a spec in my current project that requires us to advise the
In my current project, Workflows have comments. Please have a look at the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.