Re: C# inheritance broken?



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


.



Relevant Pages

  • Re: C# inheritance broken?
    ... The design can't be broken, ... my problem is loading a MyDocument from a file. ... }I can certainly write a new Load method to override the base method, ... public static MyDocument Load(string FileName) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... to create a new Document object. ... if they design one that requires you to ... don't have any problem creating a new MyDocument object when I need it; ... public static Document Load(string FileName); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... ....and about the Toyota car, if they design one that requires you to ... that design is broken. ... my problem is loading a MyDocument from a file. ... public static Document Load(string FileName); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is it possible to know within a function which object called it
    ... Maybe if you give more details about your design we can provide a better ... Ignacio Machin ... Mobile & warehouse Solutions. ... when it is one of the unwanted objects that called it? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... I'm still stuck with the ... fact that the third-party component's Load method returns a Document, ... that design is broken. ...
    (microsoft.public.dotnet.languages.csharp)

Loading