Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there such thing as something being 'too abstract'?

I am wondering if I am trying to abstract too much here in the name of RAD.

An example here - let's say I have a database table which has 3 models (the main model, the mapper model and the database model). Each of those extend an abstract model,mapper and db table model.

This setup works very nicely. The bulk of operations are actually in the abstract models. But, now I am wanting to abstract even more. Am I going to far?

I have already abstracted basic CRUD operations, now I am thinking about abstracting the more advanced ones.

An example of that would be fetching a few related models. Currently I would do this:

$modelOne->modelTwo(); where modelTwo is explicitly defined.

My idea was to then use either an abstract method like injectModel('modelTwo') or a magic method.

I can always build in the relevant rules to ensure my models maintain integrity...but is this too far?

Appreciate any advice.

I don't care how incoherent some of my code is; I can write clear documentation and comments in those parts.

like image 582
Damien Roche Avatar asked Oct 24 '22 22:10

Damien Roche


1 Answers

That's precisely the approach I've taken in developing my current application. And now I have a whole bunch of abstract methods and magic methods for fetching and persisting model's relationships sitting on the top of Zend_Db_Table and Zend_Db_Table_Row.

Though it felt quite alright in the beginning, it's becoming more and more complicated to support and introduce even new abstract methods, not mentioning hardships other members of the team are facing when dealing with this code (no matter how well documented it is).

This approach feels pretty much like writing my own ORM, which I definitely didn't plan for. My strongest belief now is that I should've adopted Doctrine from the very beginning.

like image 58
Vika Avatar answered Oct 31 '22 10:10

Vika