If B.Create has to be different, then you might want to think about doing:
class A {} // Note this is non abstract and creatable
abstract class Intermediary : A {}// Note this is an abstract class, put shared
methods here.
class B {} : Intermediary
class C {} : Intermediary
By calling base.Create() in B/C you now call directly down to the class A
implementation as long as you don't override the method in Intermediary. If you
do override the method in Intermediary then all you have to do is call return
base.Create() as implementation in Intermediary.
Adding full source below my sig. Note I used A,B,C,D as names where B was the
Intermediary class and C/D were you B/C classes.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog:
http://weblogs.asp.net/justin_rogers
using System;
public class A {
public virtual bool Create() {
Console.WriteLi ne("Create From A");
return true;
}
}
public abstract class B : A {
public virtual void SharedMethod1() {
}
public virtual void SharedMethod2() {
}
}
public class C : B {
public override bool Create() {
Console.WriteLi ne("Create From C");
return base.Create();
}
}
public class D : B {
public override bool Create() {
Console.WriteLi ne("Create From D");
return base.Create();
}
}
public class Tester {
private static void Main(string[] args) {
C c = new C();
c.Create();
D d = new D();
d.Create();
}
}
"Hadi" <ha**@hadi.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hello,
Say I have three classes inheritance A <-- B <-- C
And in A I have the Create method:
class A
{
public override bool Create()
{
// do stuff
return true;
}
}
class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}
// do stuff.
return true;
}
}
Now in class C
class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}
Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().
I need to do this weird inheritance because C shares a lot of methods, and
logically extends B .. but in creation C is totally different from B.
Thanks for any help.
Hadi