Re: C# inheritance broken?
- From: "Ignacio Machin \( .NET/ C# MVP \)" <machin TA laceupsolutions.com>
- Date: Fri, 26 Jan 2007 13:51:20 -0500
Hi,
<groups@xxxxxxxxxxxxx> wrote in message
news:1169835664.748921.198320@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Andy,
|
| Thanks for your response. My assertion is that the DESIGN is broken!
There is nothing wrong with teh design of C#.
What is broken is the design of the class you are trying to use :)
| But I'll settle for a work-around, if there is one.
|
| If I understand your suggestion, I've already tried this. But...I
| don't have any problem creating a new MyDocument object when I need it;
| my problem is loading a MyDocument from a file. There is only one
| method in Document that does this:
|
| class Document
| {
| public static Document Load(string FileName);
| }
Bad Design maybe?
If you do this you are certainly limiting yourself in that no derived class
will be able to override Load()
| I can certainly write a new Load method to override the base method, as
| follows:
|
| class MyDocument : Document
| {
| public static MyDocument Load(string FileName)
| {
| return Document.Load(FileName);
| }
| }
|
| The problem is, the above code won't compile, because it is not valid
| to cast the Document returned by Document.Load to a MyDocument.
|
| Does that make sense?
YES, and let me tell that again YES, IT DOES !
Not only that but it's the same IN ALL OTHER OOP LANGUAGES.
a MyDocument is a Document, the opposite (what you are trying to do) is not
true.
--
Ignacio Machin
machin AT laceupsolutions com
.
- References:
- C# inheritance broken?
- From: groups
- Re: C# inheritance broken?
- From: Andy
- Re: C# inheritance broken?
- From: groups
- C# inheritance broken?
- Prev by Date: Re: C# inheritance broken?
- Next by Date: Re: C# inheritance broken?
- Previous by thread: Re: C# inheritance broken?
- Next by thread: Re: C# inheritance broken?
- Index(es):
Relevant Pages
|
Loading