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

  • SEARCH
  • Home
  • 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 6215535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:04:31+00:00 2026-05-24T07:04:31+00:00

So mainly I’m looking for a best practices sort of answer here. I have

  • 0

So mainly I’m looking for a best practices sort of answer here. I have a system which is basically a set of rules, some data, and a manager to make sure the data follows the rules. Pretty simple. I’m trying to figure out the best way of handling saving and loading of the rules. For a first attempt, I have an interface called IRule which all the rules inherit.

interface IRule
{
  /* all rules inherit this */
  string RuleName {get;}
}
interface IRuleTypeA : IRule
{
  /* Type A Rules */
  double[] Data;
}

interface IRuleTypeB : IRule
{
  /* Type B Rules */
  double[,] Data;
}

public static class IRuleExtensions
{
  XElement AsXml(this IRuleTypeA ruleA)
  {
    //format my data my way and return an XElement representation
    return new XElement(...);
  }
  XElement AsXml(this IRuleTypeB ruleB)
  {
    //format my different data in a different way and return an XElement
    return new XElement(...);
  }
  XElement AsXml(this IRule rule)
  {
    object definition = null;
    if(rule is IRuleTypeA)
      definition = (rule as IRuleTypeA).AsXml();
    else if(rule is IRuleTypeB)
      definition = (rule as IRuleTypeB).AsXml();
    return new XElement("RuleDefinition", new XAttribute("name", rule.RuleName),
                         definition);
  }
}

So here, I’m putting the saving functionality into the class being saved. I was about to implement a similar loading mechanism that will take each element and construct a rule. Before I do that, I wanted to see if there were best practices about this. Should I instead create a separate system which would take a rule, interrogate it, then save that to XML and use a factory-type system to consume the Xml to construct the objects back?

interface RuleToXmlAdaptor
{
  XElement AsXml(IRule rule);
  IRule FromXml(XElement element);
}
class RuleAToXmlAdaptor : RuleToXmlAdaptor
{
  XElement AsXml(IRule rule) { return AsXml(rule as IRuleTypeA); }
  XElement AsXml(IRuleTypeA rule);
}

I go back and forth between these methods not really sure when to use one or the other or if there’s a better solution still.

I do not want to use Serialization because the file type is likely to change continuously and I can manage the compatibility fairly simply this way.

  • 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-24T07:04:32+00:00Added an answer on May 24, 2026 at 7:04 am

    I don’t think the class itself should know anything about how it can be serialized. That violates the single-responsibility principle. Think about the case where tomorrow a new awesome serialization format comes out, say SoupML. If you let someone outside the object take care of the serialization, then it should be really easy to make your system work well with SoupML and you won’t even have to change the existing rule models.

    Ideally only those units that explicitly consume XML should be aware of XML, this way your system can be made out of units that wouldn’t care about the format but only about the interfaces. Somewhere later they will be told which serializer/deserializaer to use (Inversion of Control). Having it this way also supports open-close principle. You won’t have to pry open stuff for modification, but it will be open for extension.

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

Sidebar

Related Questions

We have a magento store which mainly features the contents and it has only
I am mainly looking for good development practices specially when working in conjunction with
We have a (mainly) C#/WPF application that invokes some C++ libraries via interop. For
I'm looking mainly at things like new SQL syntax, new kinds of locking, new
Mainly from feature-set standing point, as well as similarity of method names/working logic/verbosity ?
i mainly use PHP and I have been coding using it for a while.
I have mainly seen sites using widgets on sidebars or inside multi-column layout. However,
This question is mainly out of curiosity (I have a different working solution to
Mainly looking for PHP minifier. Online copy > paste > output, would be a
I mainly do .Net development but have just bought an Apple Mac Book Pro

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.