开发者

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

开发者 https://www.devze.com 2023-02-03 02:10 出处:网络
I am wondering if I am trying to abstract too much here in the name of R开发者_如何学PythonAD. An example here - let\'s say I have a database table which has 3 models (the main model, the mapper mode

I am wondering if I am trying to abstract too much here in the name of R开发者_如何学PythonAD.

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.


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.


Didn't Einstein say "Everything should be made as simple as possible, but not one bit simpler."?

How my simple mind interprets that is to only abstract as far as you need to. If you compare popular frameworks, which ones do you think abstract too far as to focus your attention away from what you are doing? I would argue ASP.NET and Java tend to do this much more so than PHP or node.js. Also, if you compare XML with JSON this is probably more obvious that too much abstraction leads to a heavier payload and a heavier intellectual weight. I don't see the value of being a scholar of abstraction over doing.

KISS

0

精彩评论

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