玩!框架使用< lot>静力学 [英] Play! framework uses a <lot> of statics

查看:107
本文介绍了玩!框架使用< lot>静力学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Waaah,Play!框架有很多静态方法。在我上学的地方,我们被告知永远不会使用任何静力学,但玩!使用它就像没有明天一样。那是不是很好?若然,为什么?

Waaah, the Play! framework has so many static methods. Where I go to school, we were told never ever to use any statics, yet Play! uses it like there's no tomorrow. Is that somehow okay? If so, why?

我们(7人和我)正计划使用Play!涉及Web应用程序的项目框架。我们决定玩Play!因为它看起来很有趣,我们所有人都已经知道Java并且任务很难,所以我们想要专注于实际的任务,而不是学习如何用不同的语言编程。

We (7 people and I) are planning to use the Play! framework for a project involving a web app. We decided to do it with Play! because it looks quite fun to do, all of us already know Java and the assignment is pretty hard so we wanted to focus on the actual assignment rather than also learning how to program in a different language.

然而,我们总是被告知从来没有在我们开发的任何Java程序中使用'static',但是当我看到Play时! ......嗯......大约一半的方法都是静态的。 < / exaggeration>

We were always told, however, NEVER EVER to use 'static's in any Java program we developed, but when I look at Play! ... Well... about half the methods are static. </exaggeration>

我想,至少,我们可以使用单例对象(通过使用Scala,例如^^)来编程我们的项目,但是我非常担心框架本身实际上有多少静态。

I suppose, at the very least, we could use singleton objects (by using Scala, for example ^^) in order to program our project, but I'm quite concerned at how many statics there actually are in framework itself.

所以,我应该关注这个吗?玩的方式!开发人员编程使它成为所有这些静态不会造成问题的?

So, should I be concerned about this? Did the way the Play! developers programmed it make it so that all these statics don't pose a problem?

(例如,这个主题有一个关于为什么不惜一切代价应该避免静态成员的咆哮。)

(For example, this thread has a rant about why static members should be avoided at all costs.)

推荐答案

只有在有意义的情况下才使用静态方法:

Play uses static methods only when it makes sense:


  • 在控制器中层,因为控制器不是面向对象的。控制器充当HTTP世界(无状态,基于请求/响应)和完全面向对象的模型层之间的映射器。

  • 在工厂方法的模型层中,如findAll (),count(),create()当然不依赖于任何特定实例

  • 在一些提供纯实用函数的play.libs。*类中

这篇关于玩!框架使用&lt; lot&gt;静力学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆