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

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

问题描述

哇哦,好戏!框架有这么多静态方法.在我上学的地方,我们被告知永远不要使用任何静力学,但要玩!像没有明天一样使用它.这样可以吗?如果是,为什么?

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 程序中使用静态",但是当我查看 Play 时!...嗯...大约一半的方法是静态的.</夸张>

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?

(例如,this thread 有一个关于为什么应该不惜一切代价避免使用静态成员.)

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

推荐答案

Play 仅在有意义时才使用静态方法:

Play uses static methods only when it makes sense:

  • 在控制器层,因为控制器不是面向对象的.控制器充当 HTTP 世界(无状态,基于请求/响应)与完全面向对象的模型层之间的映射器.
  • 在工厂方法的模型层中,例如 findAll()、count()、create(),它们当然不依赖于任何特定实例
  • 在一些提供纯实用功能的 play.libs.* 类中

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

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