Re: Modifier mixture

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Jon wrote:
AD <adriaandavel@xxxxxxxxxxx> wrote:
I have a base class that is inherited often, and I am struggeling to
chose the correct access modifiers.

What I am trying to do is to force all inherited classes to have a
function of the same name as one of the functions in base class (like
an abstract function), but I would also like to add a body to the
function in the base class (like a public/private/protected function),
how would I go about it?

You can't.

What exactly are you trying to achieve? One pattern is to have one
concrete method, and an abstract one which is called by the concrete
one.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Hi Jon, thanks for the post

What I'm trying to do is to use a class as an abstract class, but still
be able to use the class as a normal class. This is sounding like a
virtual class, but with the virtual class overrides are optional.

My current design is that my base class carries the "generic"
functionality of most applications developed by our company, so when it
is inherited it exposes that functionality to all consumer classes. Now
I would also like my base class to enforce certain functions in all
consumer classes (for example a function called "Install" that will
create all SQL Stored procs used by the module) to improve consistancy
across classes and open up some reflection possibilities.

The only way I see this happening is creating a copy of my base class
as a true abstract class and consumer inheriting that, but that would
cause code duplication that I'm trying to avoid.

Does this make any sense?

.



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: Factory method
    ... The base class must not create the children. ... If you don't want a public constructor, then define a Factory ... >I have an abstract class, and a set of classes that inherit from my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inheritance question
    ... Only problem is the Microsoft wrote the Mammal base class. ... >>Now from an entire OOP design point of view I'd say that if you are ... What would you do with a Platypus class that inherits a ... > abstract class Monotreme:Mammal ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Getting type of inheriting class from static methods in base class
    ... > I can't really have typeofin a member of the base class CBase, ... > that would ruin the whole idea of inheriting. ... > impossible to verify at compile time. ... Encoding u = UnicodeEncoding.Unicode; ...
    (microsoft.public.dotnet.general)
  • Re: Basic Web Design Question
    ... 2005 or continue with inheriting a base class... ... Create a base class that all your pages inherit from, ... Use user controls, or custom server controls. ... A basic question though - is there a way of having 'common' elements on ...
    (microsoft.public.dotnet.framework.aspnet)