soyut sınıf php tekiz

0 Cevap php

Ben basit bir sorum var. Ben soyut bir sınıf uygulayan bir Singleton kullanmak. Yerine ben oluşturmak istiyorum somut biri soyut sınıf () Yöntem ve değişken $ _instance getInstance koymak mümkün mü?

İşte benim kod:

<?php
class Command_Log extends Command_Abstract {
    private static $_instance=null;

    public static function getInstance() {
        if (self::$_instance==null)
        self::$_instance=new self();
        return self::$_instance;
    }

    protected function realExecute() {
    }

    protected function realSimulate($fileHandle) {
    }

}

ve

<?php

abstract class Command_Abstract implements Command_Interface {
    protected $_data=array();
    //private static $_instance=null;
    protected $_isExecuted=false;
    protected $_execute=false;


    public function enableExecute() {
        $this->_execute=true;
        return $this;
    }

    protected function __construct() {

    }
    protected function __clone() {}


    public function addData($data) {

        array_push($this->_data,$data);
        return $this;
    }

    abstract protected function realExecute();

    abstract protected function realSimulate($fileHandle);

    public function execute() {
        if(!$this->_isExecuted && $this->_execute) {
            $this->_isExecuted = true;
            $this->realExecute();
        }
    }

    public function simulate() {
        $exitSystem = false;
        if(!$this->_isExecuted && $this->_execute) {
            $this->_isExecuted = true;
                $exitSystem = $this->realSimulate($fh);
            }
        }
        return $exitSystem;
    }

}

Ben komutların birçok uygulama var, bu yüzden benim uygulamalarında her yerde gereksiz kod istemiyorum. Evet nasıl söyle lütfen, soyut sınıf içinde bu iki şeyi koymak mümkündür.

Eğer değilse o possbile değil neden bana bunu açıklayınız. Yoksa ben zaten bunu yapmak için bir şey değiştirmek gerekir.

selamlar

0 Cevap