开发者

Basic Oriented Object Modelization in PHP5

I use zend framework and I would like to have your advice to modelize my classes. I have 3 classes Patrimony.php Project.php and Version.php. Version extends Project extends Patrmimony. In other hand I have a folder structure like this /data/patrimonies/projects/versions/

I don't know if I have to use a Design Pattern or something like that, if patrimony have a variable $_project which contains an instance of project, how do I instanciate my class (__construct() params). In brief I am very confusing with OOP.

Please light me :-)

class Admin_Model_Patrimony { }

class Admin_Model_Project extends Admin_Model_Patrimony { }

class Admin_Model_Version extends Admin_Model_Project 开发者_运维知识库{ }


I have look to the composition pattern and it seems it is interessant when you want to compose with different number of leaves. In my case There are always one patrimony one project and one version for any entities.

My goal is sometimes I just use informations about a patrimony othertimes I only needs information about project.

I show you how I have design my classes, see the last lines for execution process and expected values. I think this code doesn't work so how do I do to set variable of the parents when I instanciate a child?

// Version
class Version extends Project
private $this->_patId;
private $this->_proId;
private $this->_verId;
{
public function __contruct($patrimonyId, $projectId, $versionId)
{
$this->_patId = $patrimonyId;
$this->_proId = $projectId;
$this->_verId = $versionId;
}
public function getVersionId()
{
return $this->_verId;
}

// Project
class Project extends Patrimony
private $this->_patId;
private $this->_proId;
{
public function __contruct($patrimonyId, $projectId)
{
$this->_patId = $patrimonyId;
$this->_proId = $projectId;
}
public function getProjectId()
{
return $this->_proId;
}

// Patrimony
class Patrimony
private $this->_patId;
{
public function __contruct($patrimonyId)
{
$this->_patId = $patrimonyId;
}
public function getPatrimonyId()
{
return $this->_patId;
}

// Execution
$version = new Version(1,2,3);
$version->getVersionId(); // should return 1
$version->getProjectId(); // should return 2
$version->getPatrimonyId(); // should return 3

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜