Reputation: 5651
According to Zend quick start guide I need three classes (A model, A mapper class and a table gateway class) to implement the Table Data Gateway pattern. But is this a good approach?
Right now this is how I implement the pattern.
class Application_Model_Person(){
private $_name;
public function getName();
public function setName($name);
}
class Application_Model_PersonMapper extends Zend_Db_Table_Abstract {
public function fetch();
public function search();
public function save(Application_Model_Person $person);
public function delete();
}
So I have a model class with all getter/setter methods and another class which extends the Zend_Db_Table_Abstract class and performs all crud operations. I like this approach as it reduces the number of classes and is easy to follow. But is this a proper way of doing it?
Also what advantages will I get if I use the approach in the Zend quick start guide?
Upvotes: 0
Views: 1048
Reputation: 3128
It depends on the size of your project really. ZF is what I call "enterprise ready", i.e. build a large web application. In my mind and following these pattern I can scale almost infinitely. However, for many smaller projects this could be overkill.
The only problem I see with your example is extending a mapper to a DbTable which is following the common pattern just wrong. For a smaller project you could have your Models (external--application view) and access your DbTable classes (internal--Db gateway) directly and skip the mapper.
If for whatever reason later on you decide you need mappers for certain tables you should be able to implement them rather easily.
Upvotes: 2