2009年1月30日星期五

[fw-db] OOP Design question related to Zend_Db_Adapter

I'd need the help of some good designer/architect.

We will be switching to a replication database system (Master/Slaves) and I
will me modifying our company's framework (which is built on top of Zend
Framework) so that our database adapter supports Master/Slave mode, meaning
the read-only operations will be done on a slave, and all writes will be
done on the master. So the adapter will support theorically two active
connections at the same time (won't connect to more than one slave
throughout it's life). So this adapter will take a list of possible
connections, you'll specify which one(s) is/are the master(s), and which one
is/are the slave(s).

I have design issues here. I'm a purist in OOP and try to do things right,
but here's I'm kind of hitting a wall.

My first idea was to make a MyCompany_Db_Adapter_Abstract which would not
derive from anything and would only be a wrapper around all methods from
Zend_Db_Adapter_Abstract and would call the actual method on the write
server or read server depending on the operation. It would internall create
a Pdo_Adapter_MySql (when you use it in a derived MySQL adapter class) and I
would call the actual adapter through my wrapper and call the method on it.
In theory that's good because then you don't derive from a class which is
made for *single* connections... but this leads me to another problem, I
want to use classes like Zend_Db_Table and this class requires a descendant
of Zend_Db_Adapter_Abstract to be passed. So having my own adapter which
doesnt derive from Zend_Db_Adapter_Abstract would make my adapter not usable
with other Zend_Db classes...

Which leads me to the second solution, which is to derive from
Zend_Db_Adapter_Abstract. But this causes other problems.
Zend_Db_Adapter_Abstract is built with single connection in mind. It has a
_connect method which connects to a single specific server. I would need to
rewrite a bunch of methods, and would end up with lot of 'waste' in the
class. But the major problem is that from this point, if there are
modifications made to Zend_Db_Adapter_Abstract, I will need to recheck my
own MyCompany_Db_Adapter_Abstract to make sure it's in synch with it's
parent, because a few methods will have been completly rewritten and thus
become independant. Also, overriding a method without calling the parent is
bad practice, it's doable but it's really bad practice, you end up paying
the price for it when you use it too much.

Ideally, Zend Framework would come up with it's own "replication" DB
Adapter, but for now I'm a bit puzzled at what the best solution would be.
--
View this message in context: http://www.nabble.com/OOP-Design-question-related-to-Zend_Db_Adapter-tp21754135p21754135.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: