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 95721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:42:09+00:00 2026-05-10T23:42:09+00:00

When an object has various formats (XML,CSV) it can be represented in, where should

  • 0

When an object has various formats (XML,CSV) it can be represented in, where should one store knowledge of those formats.

Should the object have knowledge of how it’s represented in XML (i.e. letting the object convert itself through some method on the object such as GetXML()). Is this too much knowledge for the object and should this be stored externally in a repository/service/other layer?

If it is stored in a repository, what happens in the use case where the XML representation of the object must be persisted to a database along with other information, e.g.:-

insert into order values(1, '2004', <order><amount>2</amount><price>19.99</price></order>);

…the knowledge of the object’s XML structure would be in the XML repository, however the SQL repository would also need this knowledge, and this seems like duplication.

I am unsure as to whether the service layer should be holding object representations either, as it does not seem like this is business logic.

What is the recommended implementation for this use case?

  • 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. 2026-05-10T23:42:10+00:00Added an answer on May 10, 2026 at 11:42 pm

    Generally speaking you want the object’s XML (or other…) formatting code to be separate for the object itself. The practical reason for this is wanting to have more than one XML representation (say a summary and detailed representation). If these methods where all part of the object’s API then you start having:

    public String GetShortXml(){ ... } public String GetFullXml(){ ... } public String GetCsv(){ ... } public String GetJson(){ ... } 

    As part of the API of every single business object and that gets ugly fast. Furthermore this violates the single responsibility priciple as each class is responsible for both what id does and representing itself as XML, JSON, CSV, etc.

    Thus, it is often best to have a class that knows how to format the business objects you care about and have a SummaryXmlFormatter, DetailedXmlFormatter, CsvFormatter, JsonFormater, etc.

    You can go one step further and have your objects implement an IFormattable interface (the following is an adaptation of the visitor patter which gives us double dispatch goodness):

    public interface IFormattable {     public String Format(IFormatter formatter); } 

    with implementations like:

    public String Format(IFormatter formatter){     return formatter.FormatBusinessObjectOne(this); } 

    with the IFormatter interface defined thusly:

    public interface IFormatter{     public String FormatBuisinessObjectOne(BusinessObjectOne boo);     public String FormatBuisinessObjectTwo(BusinessObjectTwo bot);     ... } 

    Which would allow your formatting calls to be dispatched polymorphically. Depending on your requirements may or may not be useful (do you ever hold a collection of different types and thus require polymorphic dispatch or is overloading enough?).

    Your calls to format would then look like:

    IFormatter formatter = new XmlFormatter(); BusinessObjectOne boo = new BusinessObjectOne(...);  // With visitor like double dispatch String xml = boo.Format(formatter);  // Without  String xml = formatter.FormatBusinessObjectOne(boo);  // With overloading String xml = formatter.Format(boo); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 87k
  • Answers 87k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You just need to search a bit ahead and behind… May 11, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer It all depends on how things are going to be… May 11, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer well it turned to be as simple as something such… May 11, 2026 at 5:30 pm

Related Questions

My program, alas, has a memory leak somewhere, but I'll be damned if I
I have a MDI application written in Delphi 2007. If the user exits a
I'm working on a project that has a rich object model with various sets
The Question My question is: Does C# nativly support late-binding IDispatch? Pretend i'm trying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.