Re: oops questions c#
Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance
parez wrote:
I want a method in my base class to be overriden by all derived
classes.My base class cannot be a abstract class. Also I dont want to
explicitly implement an interface for all derived classes.
How do i do it?
Can i just have one abstract method in a regular class?
What is the reason for not wanting an abstract base class?
Working on the assumption it is legit, a simple solution would be to mark
the method as virtual in the base class and have it throw a
NotImplementedException. The problem with this is you won't know until
runtime that you might have forgotten to override the method in a derived
class.
--
Tom Porterfield
.
Relevant Pages
- Re: Abstract class or interface?
... I try to make the decision based on the relationship of the derived class to the base class. ... If the derived class "can act like" the type of the base class, I'd lean towards an interface. ... I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract class. ... (microsoft.public.dotnet.languages.csharp) - Re: Abstract class or interface?
... >derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ... and rotate "things" along all three X, Y, and Z coordinate axis. ... (microsoft.public.dotnet.languages.csharp) - Re: Abstract Base Classes vs Interfaces?
... an abstract class is the only choice. ... You can take any class and derive from it adding in an interface ... > doesn't have to be derived from any particular base class. ... I think ICollection is a good example of the ambiguity between ... (microsoft.public.dotnet.languages.vb) - Re: Abstract class or interface?
... > I'm still trying to figure out concrete reasons to use one over the other. ... > in its methods and derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ... (microsoft.public.dotnet.languages.csharp) - Re: Alternative to Interface?
... > this method to the interface and all involved classes. ... I declared my base class as MustInherit, and into it I put all of the ... derived classes, so I declared these as MustOverride. ... declare it as Overridable instead of MustOverride, ... (microsoft.public.dotnet.languages.vb) |
|