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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:44:39+00:00 2026-06-14T21:44:39+00:00

I have some object model(e.g. commands) which can be marshaled to some textual representation.

  • 0

I have some object model(e.g. commands) which can be marshaled to some textual representation. I have two options:

  1. Assume that every subclass of Command will correctly override “toString”
  2. Create interface with “marshal” and “unmarshal” methods that every child will be ought to implement.

Which option is better for such delegation? I mean, toString has really close meaning, but it doesn’t give me a guarantee that child class just doesn’t use standard implementation of toString.

Thanks

  • 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-06-14T21:44:40+00:00Added an answer on June 14, 2026 at 9:44 pm

    I think the approach with explicit methods is far superior. You’ve pretty much nailed the reasons:

    Assume that every subclass of Command will correctly override “toString”

    Every single maintenance programmer to touch the code will need to be aware of this assumption. If they suddenly decide that it would be nice that some class’s toString() included an additional piece of information (say for debugging), the code will unexpectedly break.

    Create interface with “marshal” and “unmarshal” methods that every child will be ought to implement.

    This makes the API explicit, hard to fail to implement, and much harder to accidentally break or misuse.

    It also means that certain errors can be caught at compile time. You can have a method that takes IMarshallable, and the compiler won’t let you pass anything that doesn’t implement the interface. With the first approach, every object has a toString() method, and there’s no way for the compiler to know whether a particular object’s toString() implements your marshalling protocol. This means that it can’t diagnose this type of error at compile time.

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

Sidebar

Related Questions

I have a data model object User . My app also has some other
Let's say I have some model objects that resemble this: public class FooModel {
I have some object that's been added to the body of my page via
I have some object that is instantiated in code behind, for instance, the XAML
I need to have some object hanging around between two events I'm interested in:
How can I use LINQ to achieve the following? I have some c# object
I have some classes that look like this: MODEL public abstract class BaseEntity<O extends
Propose to consider the following problem. Suppose we have some composite object. Are there
Question in title pretty much sums it up. I have some resource object defined
I have some trouble when I try to map object to int . My

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.