Connecting Tech Pros Worldwide Forums | Help | Site Map

is virtual necessary when inheriting from an abstract class thatimpmlements an interface?

Dan Holmes
Guest
 
Posts: n/a
#1: Jul 17 '06
Suppose i have this class declaration:

public abstract class ConfigurableComponent : Component, IConfigure

if IConfigure has a method with this signature:

List<ParameterListParameters(Identity identity)

Would i need to implement it in the abstract class with as virtual in
order for it to be overrideable in a descendant class?

public virtual List<ParameterListParameters(Identity identity)

dan

Where in the docs would this kind of stuff live? I don't know how to
find this kind of theory.
Joanna Carter [TeamB]
Guest
 
Posts: n/a
#2: Jul 17 '06

re: is virtual necessary when inheriting from an abstract class thatimpmlements an interface?


"Dan Holmes" <danholmes@bigfoot.coma écrit dans le message de news:
epPdsudqGHA.5012@TK2MSFTNGP03.phx.gbl...

| Suppose i have this class declaration:
|
| public abstract class ConfigurableComponent : Component, IConfigure
|
| if IConfigure has a method with this signature:
|
| List<ParameterListParameters(Identity identity)
|
| Would i need to implement it in the abstract class with as virtual in
| order for it to be overrideable in a descendant class?
|
| public virtual List<ParameterListParameters(Identity identity)

You can either implement interface members implicitly or explicitly :

implicit

public virtual List<ParameterListParameters(Identity identity)
{
...
}

explicit

protected virtual List<ParameterListParameters(Identity identity)
{
...
}

List<ParameterIConfigure.ListParameters(Identity identity)
{
return ListParameters(identity);
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


Tom Spink
Guest
 
Posts: n/a
#3: Jul 17 '06

re: is virtual necessary when inheriting from an abstract class thatimpmlements an interface?


Dan Holmes wrote:
Quote:
Suppose i have this class declaration:
>
public abstract class ConfigurableComponent : Component, IConfigure
>
if IConfigure has a method with this signature:
>
List<ParameterListParameters(Identity identity)
>
Would i need to implement it in the abstract class with as virtual in
order for it to be overrideable in a descendant class?
>
public virtual List<ParameterListParameters(Identity identity)
>
dan
>
Where in the docs would this kind of stuff live? I don't know how to
find this kind of theory.
If you want your method to be overridable in derived classes, then yes, you
must apply the 'virtual' modifier to the method declaration. If you want
to force derived classes to override the method, then apply the 'abstract'
modifier to the method declaration.

The interface is implemented on the class to which you specify in the class
declaration, i.e. on the class ConfigurableComponent in your case. Derived
classes in order to override your implementation need to be given the
virtual method.

--
Hope this helps,
Tom Spink

Google first, ask later.
Closed Thread