简体   繁体   中英

A java class only with “private final static” variables.. Is it a good idea?

I just want to know, since I have a lot of private final static variables in my 3 classes, if It is a good idea to put them in just one classe like this :

public class Definicoes 
{
    /*
    * Definições da Janela de Jogo
    */

    public final static String nomeJanela;
    public final static short janLargura;
    public final static short janAltura;
    public final static byte tabLinhas;
    public final static byte tabColunas;
    static
    {
    nomeJanela = "JFindPairs - 0.3";
    janLargura = 480;
    janAltura = 480;
    tabLinhas = 4;
    tabColunas = 4;
    }

    /*
    * Definições do Tabuleiro e respectivas Cartas
    */

    public final static byte numeroCartoes;
    static
    {
        numeroCartoes = 16;
    }
}

Thanks in Advance for any help. Luis Da Costa

I would put them in one place if they all have to be the same. Otherwise, I would keep the constants where they are used.

这就是我的方法,将它们全部放在一个位置是很有意义的,以防万一您需要在某个时间点返回并更改它们,而不必在类的负载中搜索1个变量:)

When they start as private ie they are used only in a single class, they should stay there.

If they need to get accessed by different classes there is probably some concept hiding. The concept might manifest itself as a class with just public static final variables, but more likely it will split in multiple classes (at least that is my experience). Unfortunatly there is now way to tell with out knowing more about your program.

这样做是完全有效的,但是它会破坏OOP设计的概念,以解耦属于特定类的变量/常量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM