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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:59:15+00:00 2026-05-23T11:59:15+00:00

I am implementing IXmlSerializable in an immutable class. To keep the class immutable I

  • 0

I am implementing IXmlSerializable in an immutable class. To keep the class immutable I am implementing the interface explicitly, so as to hide the methods, and using a static ReadXml() method which encapsulates the ReadXml(XmlReader reader) method and, instead, returns a new instance of my class. However, and supposing the class is called ClassA, the way I am forced to implement IXmlSerializable implies that the statement

((ClassA)((IXmlSerializable)(ClassAObject)).ReadXml(reader))

actually mutates the ClassAObject since, inside IXmlSerializable.ReadXml I am assigning to parameters of an already created object. That being, can ClassAObject still be considered immutable?

  • 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-23T11:59:16+00:00Added an answer on May 23, 2026 at 11:59 am

    No.

    Explicitly implementing interfaces is not meant for “hiding” methods – just for avoiding ambiguities when two interfaces define members with the same signature. The “hiding” aspect is also usable, but only to prevent mistakes in your own code – you have to explicitly cast the object, which means that you know what you are doing.

    Added: However… maybe you can get pretty close to an immutable object by “locking” it after ReadXml() has been called, so further calls to it would throw an exception. Hence the object becomes immutable after it has been read. It would be great if you also locked the object if it was constructed by another constructor than the parameterless one. Depending on why you want the immutability in the first place, this could suit your needs.

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

Sidebar

Related Questions

I'm implementing the ReadXml() method of IXmlSerializable and I figure using XPath is probably
when implementing/using methods that return or work with instances of objects, what is the
Implementing Interface just provide the skeleton of the method. If we know the exact
implementing publishActivity in PHP using the REST API using this code: $activity = array(
While implementing a design using nested generic collections, I stumbled across those limitations apparently
I have a class that I serialize/deserialize using XmlSerializer . This class contains a
When implementing a MessageFactory class to instatiate Message objects I used something like: class
Im implementing a B-tree in C++,I have a stack which saves pairs . my
I recently read the IXmlSerializable interface information on MSDN and was a little confused
Implementing the basic algorithm using last array as a pivot in Java, is it

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.