C # alternative to abstract

How to make derived forms implement the methods of the base class without making it abstract?

Received error: "The designer must create an instance of type" X ", but he cannot, because the type is declared as abstract." Thank you in advance.

+3
source share
4 answers

I would create an interface so that each form can implement it. Could you tell us more about your problem?

+12
source

You cannot force a class to override a base class method unless it is marked abstract, which also requires the base class to be abstract. Have you thought about defining an interface for these methods?

+3
source

, , . , AS3, , , :


public class PyramidenMain extends ProbabilityGame implements IProbabilityGame{
    public function PyramidenMain(){
        super(this);
        super.initialize();
    }   

    //implement interface
}

public interface IProbabilityGame{
        function getGame():MovieClip;
        function customInit():void;
        function customLoginSuccessful():void;
        function customLoginError(xml:XML):void;
        function customShowError(msg:String):void;
        function createDemoProtocol():IProtocol;
    }

public class ProbabilityGame {
    public function ProbabilityGame(game:IProbabilityGame) {
        if(game == null) {
            throw new Exception("unmet requirement, parameter containing an instance of IProbabilityGame");
        }
        _game = game;
    }

    public function initialize() {
        //do some logic
        _game.customInit();
    }
}
+2

You can override the base class and define abstract or virtual methods. Perhaps this is what you want. This is reality in a work environment.

0
source

All Articles