|
-
Oct 28th, 2009, 01:22 PM
#1
Serializable class
Hello guys and gals,
I've written classes with serializable attribute before but all of them were just "standalone" classes. By saying "standalone", I mean the class itself does not refer to other custom classes within the same application.
Now I have a need to write a serializable class that DOES refer to my other custom classes. For example, I have ClassA and ClassB. ClassB will be serializable. One of the properties in classB returns a ClassA object. My question is, in order for classB to be serializable, does ClassA also needs to be serializable?
Thanks for any inputs.
Stanav.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 28th, 2009, 02:33 PM
#2
Re: Serializable class
I don't believe so.
[edit]
I should explain my thinking. You could create a new non-serializable class with a property that holds a dataset object, which is serializable.
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Oct 28th, 2009, 03:17 PM
#3
Re: Serializable class
For a moment I read that backwards.... W_B is right, the containing class doesn't need to be serializable. Been there, done that. I have a couple t-shirts.
It's the going the other way that isn't as straight forward.
-tg
-
Oct 28th, 2009, 06:23 PM
#4
Re: Serializable class
If a method returns a type, it doesn't have any impact on serializability. If a type is a member of a different type, then for the containing type to be serialized, all of its members have to support serialization. However, since you said that B returned an A, that sounds like a method returning a type, which has nothing to do with serialization.
My usual boring signature: Nothing
 
-
Oct 29th, 2009, 07:09 AM
#5
Re: Serializable class
Shaggy, it's a property in ClassB that has ClassA type... I don't know if a property would make any difference than a method (function)...
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 29th, 2009, 08:54 AM
#6
Re: Serializable class
If the property creates a new instance of A and returns it, then you are all set. If the property is just exposing an instance of A that is a member of B, then A has to be serializable. The serialization only affects the data portion of a class.
My usual boring signature: Nothing
 
-
Oct 29th, 2009, 08:56 AM
#7
Re: Serializable class
Why don't you try it out?
-
Oct 29th, 2009, 08:58 AM
#8
Re: Serializable class
Yeah, the property itself isn't serialized, only the data members are.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|