473,804 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialization and Inheritance/Overriding problem

Hi people,

I'm having trouble trying to achieve something in C# and win forms, and am
looking for a little advice if anyone has a moment.

I've got two classes:

1) a base class
2) a derived class that inherits from it

The base class is designed to hold data and only data.

The derived class (which inherits the base/data) class is designed to have
more of a presentation role. It performs calculations on the data in the
base class and offers out manipulated data derived from the data in the base
class. The manipulated data is often offered through overridden properties.

That all works fine so far, now for the part I'm having problems with.

I'd like to be able to serialize both classes out as xml.

So the base class can save its data to file in xml format (and it should
save only its data, none of the presentation data).

Then the derived class can save its data to xml also, for me to match up
with an xslt file and present the data in a web brower.

The problem is, keeping the two sets of properties from the two classes
(base data and presentation data) separate and only serializing out the
fields required for the class in question.

If for example I have an object in memory as the derived class, then when I
serialize it to disk, it serializes the data from the base properties and
the data from the presentation/derived/overridden properties.

If instead I have the object in memory as the base class, then it serializes
fine, but I cannot of course access the presentation properties as they
don't exist on the base class.

Incidentally, I'm pretty confident that I've gone the right path with the
class/inheriting/serialize route for data/presentation. I'm just having
trouble getting over the final hurdle.

The only solutions that i've can think of so far is, custom attribute tags
combined with custom serialization. However, I will want to do the same
thing with several other very different classes, and it seems like one heck
of a lot of work. Can anyone suggest an easier solution?

Cheers,

Mark.
Nov 15 '05 #1
4 7012
Hi Mark,

Thanks for posting here.

I will do some research on this issue and will get back to you as soon as
possible.

Have a nice day!

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
Hi Mark,

Do you mean that you would like to serialize the "presentati on" related
properties of the derived class but do not want to serialize the "data"
related properties?

We usually use the "System.Xml.Ser ialization.XmlI gnoreAttribute" to achieve
this. If you do not like it, maybe we can use a wrapper class to wrap the
derived class and hide its "data" properties. Would you consider this a
workaround?

On the other hand, I am thinking about another idea. We can also use
"encapsulat ion" instead of "inheritanc e" here. For example, we do not use
the derived class at all. Instead, we create a wrapper class for the base
class directly and use the wrapper class to deal with those presentation
works.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
Hi Felix,

Thanks for taking the time to look into this for me and reply.

I would ideally like to serialize the properties on both the presentation
class and the data class. The aim being to serialize the data ones for
efficient saving to disk (in a .xml file) and to serialize the presentation
ones also to an .xml file but for transformation with an .xslt file for web
browser viewing.

I have been making use of the "System.Xml.Ser ialization.XmlI gnoreAttribute"
so far. Admittedly it took me three hours to work out why the
"NonSeriali zed" attribute wasn't working, and to switch over to the xml
equivalent, but I'm sure we can all be a little slow at times.

I think that your suggestion of encapsulation within a wrapper class might
be the direction that I head in. It will unfortunaely break the nice
elegant inheritance chain that I was slowly building up, but then not all
programming solutions can be 'nice' and 'elegant' if they are going to work
properly.

Thanks for the suggestion I'll give it a try.

Cheers,

Mark.
"Felix Wang" <v-*****@online.mi crosoft.com> wrote in message
news:5N******** ******@cpmsftng xa07.phx.gbl...
Hi Mark,

Do you mean that you would like to serialize the "presentati on" related
properties of the derived class but do not want to serialize the "data"
related properties?

We usually use the "System.Xml.Ser ialization.XmlI gnoreAttribute" to achieve this. If you do not like it, maybe we can use a wrapper class to wrap the
derived class and hide its "data" properties. Would you consider this a
workaround?

On the other hand, I am thinking about another idea. We can also use
"encapsulat ion" instead of "inheritanc e" here. For example, we do not use
the derived class at all. Instead, we create a wrapper class for the base
class directly and use the wrapper class to deal with those presentation
works.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4
Hi Mark,

Thanks for your reply. I agree with you that it is quite difficult to write
"nice" and "elegant" programs. It is also important to keep the programs
simple and easy to reuse.

Should you have any concerns or new findings regarding this issue, please
feel free to post here.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
5029
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
1
448
by: Tony Johansson | last post by:
Hello! Private inheritance is sometimes called implementation inheritance. If you use this private inheritance how is with the usage of overriding then. Is overriding used less often when having private inheritance then when you have public inheritance. I just want to have you opinion about this matter.
2
10775
by: Daniel Faensen | last post by:
As a good OO programmer that I hopefully am I prefer to implement against interfaces rather than classes. This is especially useful when it comes to multiple inheritance which is as you know an issue and not supported in languages as Java or C# - for good reasons. I have an object graph I want to persist using the XML serialization features of the .NET framework. The interface/class hierarchy of my business model resembles the following...
4
3138
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these data objects as XML but perserve the relationships in the XML document. For example, if my classes were: public class GenericItem { }
2
1516
by: Emmanuel | last post by:
Hi, I'm working on a c# web app and require having some code which runs in the page Load event of each page and to be reusable in other web apps. So i decided to use a Class Library which contains a class that inherits from the System.Web.UI.Page. the class contains an override of the OnLoad event in which the common code is executed.
0
1255
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk because the users could continue later on there project with the same data already filled in. So I would use the soap-serialization to store the info (the nested objects, collections, ...). I think this process will work very well, also the
6
6056
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The problem is that in my derived classes, the XML that is automatically generated is lacking the properties of the base class. For example: public class MyBaseClass { public MyBaseClass ( ) { } private string myVariable;
6
1677
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public AuthHeaderName As String Public SessionKey As String = "Default" End Class Public Class ServiceTicket:Inherits AuthHeader
11
2251
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern to illustrate this. Problem: I need to expose two lists of objects from a high-level class. I would like to expose these lists as read-only, but require write access internally.
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.