开发者

want to know about good OO-pattern

i have some code example

but just want to know this oo pattern is good or bad, or even it is not a oo...

class Manager 
{
    private $_rule_manager = null;
    private $_approver_manager = null;
    private $_value = null;
    function __construct($v_value = null)
    {
           $this->_value = $v_value;
    }
    public static function get_instance() 
    {
        if(self::$Instance === null) self::$Instance = new manager();
        return self::$Instance;
    }
    public static function check_sum($val1, $val2) {return $val1 + $val2;}

    public function get_approver_manager()
    {  
        if($this->_approver_manager === null) $this->_approver_manager = new approver_manager($this->_value);
        return  $this->_approver_manager;
    }
    public function get_rule_manager()
    {
        if($this->_rule_manager === null) $this-开发者_开发技巧>_rule_manager = new approver_manager($this->_value);
        return  $this->_rule_manager;
    }
}
class rule_manager
{
    private $_value = null;
    function __construct($v_value = null)
    {
           $this->_value = $v_value;
    }
    public function check_rule()
    { 
         $this->_value + $this->check_rule2(); 
        return true;    
    }
    public function check_rule2(){ return Manager::get_instance()->check_sum();  }
}
class approver_manager
{
    private $_value = null;
    function __construct($v_value = null)
    {
           $this->_value = $v_value;
    }
    public function generate_approval(){ return 'xxxxxx'; }
}
$manager = new Manager($val);
$manger->get_rule_manager()->check_rule();
$manger->get_approver_manager()->generate_approval();

Specialty in rule manager, it has a function call from manager but i use manager to create rule manager, and it route back to manager, seem wasting resource....


I will only comment on top design as your code is pretty bad.

That all depends on what objects will be used for. That example is not enough to determine proper OO design for application.

If you are using it as per your example, there is no need for rule/approval manager as functionality they offer could be integrated into manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜