OO php 中代码的改进
我的项目使用 php OO。我的应用程序中有很多家庭在 7 左右。所以我必须使用 switch 并在每个需要检查家庭的文件中执行此操作。所以我觉得表演受到了影响。那么有什么方法可以让我消除这些开关盒并使用一些设计模式或类似的东西。目前的想法是为每个系列都有一个单独的代码库,我对此并不完全满意。因此寻找各种选择来解决这个问题。
I use php OO for my project. I have lots of families in my application around 7. So i have to use switch and do it in each file where i need to check the family. So i feel the performance is effected because of this. So is there any way so that i can eliminate these switch cases and use some design patters or something like that. The present idea is to have a separate code base for each family, which i am not satisfied with completely. So looking for various options to solve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只能引用 Martin Fowler 的《重构:改进现有代码的设计》一书中的内容。
考虑购买并阅读这本书,它是我读过的最珍贵的作品之一。
I can only quote Martin Fowler from his book Refactoring: Improving the Design of Existing Code.
Consider buying and reading this book, it's one of the most precious works I have read.
该模式将是使用多态性进行条件重构。
我们的想法是将这些不同的家庭类型变成自己的对象。链接的文章摘自 Martin Fowler 的书重构:改进现有代码的设计< /a> 这已经在其他答案中引用了。事实上,链接的网站包含本书的全部内容。
更多信息请访问 http://www.refactoring.com/
That pattern would be Refactor Conditional With Polymorphism.
The idea is to make those various family types into objects of their own. The linked article is taken from Martin Fowler's book Refactoring: Improving the Design of Existing Code that was already quoted in that other answer. In fact, the linked site has the entire contents of the book.
Additional information can be found at http://www.refactoring.com/