在整个申请过程中,您在哪里使用Constants? [英] Where do you keep Constants used throughout your application?

查看:118
本文介绍了在整个申请过程中,您在哪里使用Constants?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接口是否可以存储我的

public static final Foo bar

你是否推断它们是从程序外部读取的?你是否为它组成了超级课程?

Do you extrapolate them to be read from outside of the program? Do you make up a super class for it?

当情况出现时你是怎么做到的?

How do you do it, when situation presents itself?

推荐答案

我将每个常量放入与它最密切相关的类或接口中(例如,因为它将通过其方法使用)。

I'd put each constant into the class or interface it's most closely related to (e.g. because it will be use by its methods).

一个非常诱人但最终非常愚蠢的想法是让一个常量类(或接口)包含应用程序中使用的所有常量。这看起来很整洁,但是对于可维护性并不好,因为你想通过它们实现的功能来分组,而不是像常量这样的技术细节(你会把所有接口都放到一个专用的包中吗?所有的抽象类?) 。

A very seductive but ultimately very foolish idea is to have one "constants class" (or interface) that contains all constants used in the application. This looks "neat" at first glance, but is not good for maintainability because you want to group things by the functionality they implement, not by technical details like being constants (would you put all interfaces into a dedicated package? All abstract classes?).

这个想法也是愚蠢的,因为对那个类/接口的任何改变(因为常量内联)都需要重建所有使用任何常量的类 - 即几乎整个应用程序。因此,应用程序越大,您需要进行此类完全重建的频率越高,所需的时间就越长。我参与了这样一个项目,这个问题导致每个开发人员每隔一天暂停15分钟......

The idea is also foolish because any change to that class/interface then (because of constant inlining) requires all classes that use any of the constants to be rebuilt - i.e. pretty much the entire app. So the bigger the app gets, the more frequently you need such a full rebuild, and the longer it takes. I worked on such a project, where this issue led to a 15 minute pause about every other day for every developer...

这篇关于在整个申请过程中,您在哪里使用Constants?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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