|
-
Jan 14th, 2010, 07:16 PM
#3
Re: Inheritance or Not
 Originally Posted by Shaggy Hiker
Is the web service immutable? I would guess that it is, or else you could just have it create a B that inherits from A, cast it to type A, and return it. It would still be a B, so you would have no issue with casting it back to a B. Of course, that would mean that the service itself would change somewhat, which is probably not that good an idea. The service is exposing an A, and every consumer should take that A and do with it as they please. Having it secretly expose a B that has been cast to an A, and only having certain people know that it is actually a B and can be cast back to a B, would be kind of cheesy, though possible.
You are correct, I cannot change it. Your idea of returning a B and then casting it to A is creative, but I agree that it is cheesy and wouldn't work if another consumer of the web service wanted it's own derived class returned.
 Originally Posted by Shaggy Hiker
I think the way you have it is the way that I would do it. One strange alternative would be to define a B that inherits from A, and which has a constructor that takes an A as an argument, then sets up its base from the argument. That would only be possible if A was designed in such a fashion that it would work, because the new B that took the return from the service would have to be able to constuct its base based on the return from the service, which is not always an option.
I was thinking of that as well, but as A grows in functionality, I don't want to have to remember to update a copy method in B. I have seen some implementations that use reflection to loop through the properties and copy them, but I would need a pretty recursive copy, as there are multiple reference type objects in A.
Thanks for the reply though.
P.S. I'd give you some rep, but apparently I have to spread it around first.
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
|