.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

MustInherit "delayed" implementation?

Is there a way to have the implementation of an abstract function (MustOverride) "delayed" to later derived class?  What I'm trying to achieve is something like this:

Public MustInherit Class FooBase
  Public MustOverride Sub SomeProc
End Class

Public MustInherit Class GooBase
  Inherits FooBase
    
  ' Does not override SomeProc
End Class

Public Class Hoo
  Inherits GooBase
    
  Public Overrides Sub SomeProc
  End Sub
End Class


Here's my workaround:

Public MustInherit Class FooBase
  Public MustOverride Sub SomeProc
End Class

Public MustInherit Class GooBase
  Inherits FooBase
    
  Public Overrides Sub SomeProc
      Throw New Exception("GooBase.SomeProc - Not implemented")
  End Sub
End Class

Public Class Hoo
  Inherits GooBase
    
  Public Overrides Sub SomeProc
  End Sub
End Class


From an organizational perspective it makes the most sense to put SomeProc in FooBase, but the implementation feels clumsy.  Comments appreciated.  BTW I'm using VS2003/1.1.
BrandonK
Tuesday, January 09, 2007
 
 
You declare it Overrides MustOverride.
Kyralessa Send private email
Tuesday, January 09, 2007
 
 
Visual Studio won't let you do that:

"'MustOverride' and 'Overrides' cannot be combined."
BrandonK
Tuesday, January 09, 2007
 
 
But that IS what I'd like to do!
BrandonK
Tuesday, January 09, 2007
 
 
Not sure why it didn't work for you; maybe you put those in the wrong place?

Public MustInherit Class FooBase
    Public MustOverride Sub SomeProc()
End Class

Public MustInherit Class GooBase
    Inherits FooBase

    Public MustOverride Overrides Sub SomeProc()
End Class

Public Class Hoo
    Inherits GooBase

    Public Overrides Sub SomeProc()
    End Sub
End Class

Note that MustOverride Overrides should be in the "middle" class, and the method shouldn't have a body (since it's MustOverride).
Kyralessa Send private email
Tuesday, January 09, 2007
 
 
I copied the code from your post and pasted it into a blank code file in Visual Studio 2003.  The same compile error resulted.

I understand EXACTLY what you're suggesting, and that was what I tried before posting, but VS won't let you combine MustInherit and Overrides.

http://msdn2.microsoft.com/en-us/library/aa290362(VS.71).aspx

<quote>
MustOverride methods cannot override other methods, and so cannot be combined with the Overrides modifier
</quote>

Is this a limitation of VS 2003/.Net 1.1?  Can you do this in VS 2005?
BrandonK
Tuesday, January 09, 2007
 
 
If it's a limitation of VS 2003, it wouldn't be the first such OO-related one I've seen.  I don't have a copy of VS 2003 to verify what you found, but I can confirm that in VS 2005 it works as I posted.  :(
Kyralessa Send private email
Tuesday, January 09, 2007
 
 
Interesting... thanks for you help.  I've been putting of upgrading Visual Studio until I release the product version I'm currently working on.  Looks like I should rethink that decision.
BrandonK
Tuesday, January 09, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz