singleton in abstract class php

khorimati

New Member
I have a simple question. I use a singleton which implements an abstract class. Is it possible to put the getInstance() Method and the variable $_instance in the abstract class instead of the concrete one I want to create?Here's my code:\[code\]<?phpclass 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) { }}\[/code\]and \[code\]<?phpabstract class Command_Abstract implements Command_Interface { protected $_data=http://stackoverflow.com/questions/3885464/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; }}\[/code\]I have many implementations of the the commands, so I don't want redundant code everywhere in my implementations. Is it possible to put these two things in the abstract class, if yes please tell me how.If not please explain it to me why it isnt possbile. Or if I need to change something to do it, anyhow.regards
 
Back
Top