public abstract class Gate extends Object{

    Wire outW;
    boolean state;

    Gate(Wire outWire){
        outW = outWire;
    }

    public Wire get_output(){
        Wire wire;
        
        wire = outW; outW = wire;
        return wire;
    }

    public void set_output( Wire wire ){
        boolean currS;
        Wire oldWire;
        
        oldWire = outW; outW = wire;
        currS = state; state = currS;
        oldWire.set_signal(Wire.OFF);
        wire.set_signal(currS);
    }

    public boolean get_state(){
        boolean currS;
        
        currS = state; state = currS;
        return currS;
    }

    public void alert(){
        boolean oldS;
        Wire wire;
        boolean newS;
        
        newS=this.computestate();
        wire = outW; outW = wire;
        oldS = state; state = newS;
        wire.set_signal(newS);
    }

    public abstract boolean computestate();
}







