Re: array, xmlserializer and inheritance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Matt Berther (mberther_at_hotmail.com)
Date: 01/25/05


Date: Tue, 25 Jan 2005 11:08:45 -0800

Hello Smola,

Im not sure your object model makes sense...

You want a class to maintain a list of instances of that class? How do you
know which one is the main class? This is very similar to the Registry pattern
from PoEAA, and in that pattern you have a separate class that handles the
registry of objects.

Once you do that, the serialization should just fall into place...

--
Matt Berther
http://www.mattberther.com
> Hi all,
> 
> I have a situation like this:
> 
> abstract class A
> {
> public ArrayList List;
> // This list will contain objects of derived classes - like B
> }
> class B : A
> {
> }
> 
> I need to serialize class B with XmlSerializer but in the class A i
> cannot define what type will go in the List (with XmlArrayItem)
> because the class is abstract and I don't know what types can be
> derived from it.
> 
> How can I define this in the class B? Is this approach ok:
> 
> class B : A
> {
> [XmlArray, XmlArrayItem (Type = typeof(B))
> new public ArrayList List;
> }
> Thanks.
> 


Relevant Pages

  • Re: Abstract class or interface?
    ... I try to make the decision based on the relationship of the derived class to the base class. ... If the derived class "can act like" the type of the base class, I'd lean towards an interface. ... I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract class. ...
    (microsoft.public.dotnet.languages.csharp)
  • XmlSerializer and DefaultValue?
    ... handmade Xml parsing code, but am having a few small issues with ... default values and derived classes. ... public int AValue ...
    (microsoft.public.dotnet.xml)
  • array, xmlserializer and inheritance
    ... // This list will contain objects of derived classes - like B ... cannot define what type will go in the List (with XmlArrayItem) because ... That's me favorite shirt. ...
    (microsoft.public.dotnet.framework)
  • Re: oops questions c#
    ... classes.My base class cannot be a abstract class. ... explicitly implement an interface for all derived classes. ... Working on the assumption it is legit, a simple solution would be to mark the method as virtual in the base class and have it throw a NotImplementedException. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Abstract class or interface?
    ... > I'm still trying to figure out concrete reasons to use one over the other. ... > in its methods and derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ...
    (microsoft.public.dotnet.languages.csharp)