none
abstract class -> base class -> derived class RRS feed

  • Question

  • Hi,

    I have one qestion about abstract class.
    my model is below ( i need instance of baseclass and derivedclass according to condition )
    and problem is some special check need to handle if it derived class called


    abstract class AbsClass
    {
    public abstract int add(int, int);
    }
    public class BaseClass : AbsClass
    {
    public override int add(int, int ) { ... }

    public void myFun ()
    {
       some common functionality
       // after few special check and then need dervied specific check
       updatedValue = myDerivedSpecificCheck(int);    // i cant make it method abstract as this is not abstract class
    }

    }

    public class Derived1 : BaseClass
    {
    public int myDerivedSpecificCheck(int)
    {
    ....
    }
    }


    Thanks and Regards,
    Nik

    Thursday, December 20, 2007 11:41 AM

Answers

  •  

    If I understand the question correctly, you can define myDervedSpecificCheck as a virtual method method in the BaseClass (you may want to change the method name) and override it in the Derived1 class. The implementation in BaseClas would simply return the unchanged value.

     

    Thursday, December 20, 2007 11:51 AM

All replies

  •  

    If I understand the question correctly, you can define myDervedSpecificCheck as a virtual method method in the BaseClass (you may want to change the method name) and override it in the Derived1 class. The implementation in BaseClas would simply return the unchanged value.

     

    Thursday, December 20, 2007 11:51 AM
  • Hi,

    Thanks, sorry for late reply

    Regards,
    Nik
    Wednesday, December 26, 2007 9:25 AM