简体   繁体   English

如何用Java制作只读数据类

[英]How to make a read-only data Class in Java

I'm building an emulator and I have a class called Emulator which has data related to fonts and a set of instructions that is put into the CPU later. 我正在构建一个仿真器,并且有一个名为Emulator的类,该类具有与字体有关的数据以及一组稍后放入CPU的指令。 However, I would like to have a "container" class that has all that information so that Emulator is shorter and more readable. 但是,我想拥有一个包含所有这些信息的“容器”类,以使Emulator更短,更易读。 Is this object oriented? 这个对象是面向对象的吗? What would be a good approach? 有什么好的方法?

final int[] fontSet = {
        0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
        0x20, 0x60, 0x20, 0x20, 0x70, // 1
        0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
        0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
        0x90, 0x90, 0xF0, 0x10, 0x10, // 4
        0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
        0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
        0xF0, 0x10, 0x20, 0x40, 0x40, // 7
        0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
        0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
        0xF0, 0x90, 0xF0, 0x90, 0x90, // A
        0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
        0xF0, 0x80, 0x80, 0x80, 0xF0, // C
        0xE0, 0x90, 0x90, 0x90, 0xE0, // D
        0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
        0xF0, 0x80, 0xF0, 0x80, 0x80  // F
};

private List<Instruction> initInstructions() {
    List<Instruction> instructions = new ArrayList<>(INSTRUCTIONS_NUM);

    add0Instructions(instructions);
    add1Instructions(instructions);
    add2Instructions(instructions);
    add3Instructions(instructions);
    add4Instructions(instructions);
    add5Instructions(instructions);
    add6Instructions(instructions);
    add7Instructions(instructions);
    add8Instructions(instructions);
    add9Instructions(instructions);
    addAInstructions(instructions);
    addBInstructions(instructions);
    addCInstructions(instructions);
    addDInstructions(instructions);
    addEInstructions(instructions);
    addFInstructions(instructions);
    return instructions;
}

private void add0Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Clears Display
        public void execute(final CPU cpu) {
            cpu.getMemoryMap().getMemory(MemoryType.DISPLAY).clear();
            Platform.runLater(new Runnable() { // TODO: NO SE SI HACE FALTA
                @Override
                public void run() {
                    display.paint(cpu.getMemoryMap().getMemory(MemoryType.DISPLAY));
                }
            });
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.get() == 0x00E0;
        }
    });

    instructions.add(new Instruction() { //Return from a subroutine
        public void execute(CPU cpu) {
            cpu.getInstPointer().set(cpu.getStack().pop() + 2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.get() == 0x00EE;
        }
    });
}

private void add1Instructions(List<Instruction> instructions) { // Set InstPointer to KKK // CHEQUEADA
    instructions.add(new Instruction() {
        public void execute(CPU cpu) {
            cpu.getInstPointer().set(cpu.getOpCode().get() & 0x0FFF);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x01;
        }
    });
}

private void add2Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Call subroutine at nnn
        public void execute(CPU cpu) {
            cpu.getStack().push(cpu.getInstPointer().get() & 0x0000FFFF);
            cpu.getInstPointer().set(cpu.getOpCode().get() & 0x0FFF);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x02;
        }
    });
}

private void add3Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Skip next instruction if Vx = kk
        public void execute(CPU cpu) {
            int position = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int data = Bitwise.getByteAsInt(cpu.getOpCode().get(), 1);

            if(cpu.getRegistry(position).get() == data)
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x03;
        }
    });
}

private void add4Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Skip next instruction if Vx != kk
        public void execute(CPU cpu) {
            int position = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int data = Bitwise.getByte(cpu.getOpCode().get(), 1);

            if (cpu.getRegistry(position).get() != data)
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x04;
        }
    });
}

private void add5Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Skip next instruction if Vx = Vy
        public void execute(CPU cpu) {
            int position1 = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int position2 = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 2);

            if(cpu.getRegistry(position1).equals(cpu.getRegistry(position2)))
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x05 && opCode.getNibble(3) == 0x00;
        }
    });
}

private void add6Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Set Vx = kk
        public void execute(CPU cpu) {
            int position = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int data = Bitwise.getByteAsInt(cpu.getOpCode().get(), 1);

            cpu.getRegistry(position).set(data);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x6;
        }
    });
}

private void add7Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Set Vx = Vx + kk
        public void execute(CPU cpu) {
            int position = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int data = Bitwise.getByteAsInt(cpu.getOpCode().get(), 1);

            cpu.getRegistry(position).set(Bitwise.getByteAsInt(cpu.getRegistry(position).get() + data, 1));
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x07;
        }
    });
}

private void add8Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Set Vx = Vy
        public void execute(CPU cpu) {
            int position1 = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 1);
            int position2 = Bitwise.getNibbleAsInt(cpu.getOpCode().get(), 2);

            cpu.getRegistry(position1).set(cpu.getRegistry(position2).get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x00;
        }
    });

    instructions.add(new Instruction() { //MUCHAS OPERACIONES LOGICAS
        public void execute(CPU cpu) { //Set Vx = Vx OR Vy
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            cpu.getRegistry(position1).or(cpu.getRegistry(position2));
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x01;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx AND Vy
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            cpu.getRegistry(position1).and(cpu.getRegistry(position2));
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x02;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx XOR Vy
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            cpu.getRegistry(position1).xor(cpu.getRegistry(position2));
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x03;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx + Vy, set VF = carry
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            cpu.getRegistry(position1).add(cpu.getRegistry(position2));
            cpu.getRegistry(0xF).set(cpu.getRegistry(position1).get() > 255 ? 0x1 : 0x0);
            cpu.getInstPointer().add(2);
        }

        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x04;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx - Vy, set VF = NOT borrow
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            cpu.getRegistry(position1).sub(cpu.getRegistry(position2));
            cpu.getRegistry(0xF).set(cpu.getRegistry(position1).get() > 0 ? 0x1 : 0x0);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x05;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx SHR 1
            int position = cpu.getOpCode().getNibble(1);

            cpu.getRegistry(0xF).set(cpu.getRegistry(position  & 0x0001).get());
            cpu.getRegistry(position).set(cpu.getRegistry(position).get() / 2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x06;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vy - Vx, set VF = NOT borrow
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);
            int sub = cpu.getRegistry(position2).get() - cpu.getRegistry(position1).get();

            cpu.getRegistry(position1).set(sub);
            cpu.getRegistry(0xF).set(sub > 0 ? 0x1 : 0x0);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x07;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = Vx SHL 1
            int position = cpu.getOpCode().getNibble(1);

            cpu.getRegistry(0x0F).set((cpu.getRegistry((position & 0x8000) == 0x8000 ? 1 : 0).get()));
            cpu.getRegistry(position).set(cpu.getRegistry(position).get() * 2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x08 && opCode.getNibble(3) == 0x0E;
        }
    });
}

private void add9Instructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Skip next instruction if Vx != Vy
        public void execute(CPU cpu) {
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);

            if(!cpu.getRegistry(position1).equals(cpu.getRegistry(position2)))
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x09;
        }
    });
}

private void addAInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Set I = nnn
        public void execute(CPU cpu) {
            cpu.getRegisterI().set(cpu.getOpCode().get() & 0x0FFF);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0A;
        }
    });
}

private void addBInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Jump to location nnn + V0
        public void execute(CPU cpu) {
            int sum = Bitwise.getByteAsInt(cpu.getRegistry(0x0).get(), 1) + (cpu.getOpCode().get() & 0x0FFF);
            cpu.getInstPointer().set(sum);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0B;
        }
    });
}

private void addCInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Set Vx = random byte AND kk
        public void execute(CPU cpu) {
            int position = cpu.getOpCode().getNibble(1);
            int data = Bitwise.getByteAsInt(cpu.getOpCode().get(), 1);
            data = Bitwise.and(data, rand.nextInt(255 + 1)); // TODO: TAMBIEN NECESITA UN RAND
            cpu.getRegistry(position).set(data);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0C;
        }
    });
}

private void addDInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision
        public void execute(final CPU cpu) {
            int position1 = cpu.getOpCode().getNibble(1);
            int position2 = cpu.getOpCode().getNibble(2);
            int height = cpu.getOpCode().getNibble(3);
            int x = Bitwise.getByteAsInt(cpu.getRegistry(position1).get(), 1);
            int y = Bitwise.getByteAsInt(cpu.getRegistry(position2).get(), 1);
            cpu.getRegistry(0x0F).set(0);

            for(int offsetY = 0; offsetY < height; offsetY++) {
                int line = cpu.getMemoryMap().getMemory(MemoryType.RAM).get(cpu.getRegisterI().get() + offsetY);
                for(int offsetX = 0; offsetX < 8; offsetX++) {
                    int pixel =  line & (0x80 >> offsetX);
                    if(pixel != 0) {
                        int totalX = x + offsetX;
                        int totalY = y + offsetY;
                        int index;

                        totalX = totalX % 64;
                        totalY = totalY % 32;
                        index = (totalY * 64) + totalX;
                        if(cpu.getMemoryMap().getMemory(MemoryType.RAM).get(index) == 1)
                            cpu.getRegistry(0x0F).set(1);
                        cpu.getMemoryMap().getMemory(MemoryType.RAM).set(index, cpu.getMemoryMap().getMemory(MemoryType.RAM).get(index) ^ 1);
                    }
                }
            }
            cpu.getInstPointer().add(2);
            //screen.setNeedRedraw(true); //ESTE BOOLEAN TIENE QUE IR EN ALGUN LADO
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    display.paint(cpu.getMemoryMap().getMemory(MemoryType.DISPLAY));
                }
            });
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0D;
        }
    });
}

private void addEInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() { //Skip next instruction if key with the value of Vx is pressed
        public void execute(CPU cpu) {
            int position = cpu.getOpCode().getNibble(1);
            int data = cpu.getRegistry(position).get();

            if(cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).get(data) == 1)
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0E && (opCode.get() & 0x00FF) == 0x9E;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Skip next instruction if key with the value of Vx is not pressed
            int position = cpu.getOpCode().getNibble(1);
            int data = cpu.getRegistry(position).get();

            if(cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).get(data) == 0)
                cpu.getInstPointer().add(2);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0E && (opCode.get() & 0x00FF) == 0xA1;
        }
    });
}

private void addFInstructions(List<Instruction> instructions) {
    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set Vx = delay timer value
            int position = cpu.getOpCode().getNibble(1);

            cpu.getRegistry(position).set(cpu.getDelayTimer().get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x07;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Wait for a key press, store the value of the key in Vx
            int position = cpu.getOpCode().getNibble(1);
            int keyboardSize = cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).size();

            for (int i = 0; i < keyboardSize; i++) {
                if (cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).get(i) == 1) {
                    cpu.getRegistry(position).set(cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).get(i));
                    cpu.getInstPointer().add(2);
                    cpu.getMemoryMap().getMemory(MemoryType.KEYBOARD).clear();
                    return;
                }
            }
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x0A;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set delay timer = Vx
            int position = cpu.getOpCode().getNibble(1);

            cpu.getDelayTimer().set(cpu.getRegistry(position).get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && ((opCode.get() & 0x00FF) == 0x15);
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set sound timer = Vx
            int position = cpu.getOpCode().getNibble(1);

            cpu.getSoundTimer().set(cpu.getRegistry(position).get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x18;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set I = I + Vx
            int position = cpu.getOpCode().getNibble(1);

            cpu.getRegisterI().set(cpu.getRegisterI().get() + cpu.getRegistry(position).get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x1E;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Set I = location of sprite for digit Vx
            int position = cpu.getOpCode().getNibble(1);
            int character = cpu.getRegistry(position).get();

            cpu.getRegisterI().set(0x0050 + character*5);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x29;
        }
    });

    instructions.add(new Instruction() { //Store BCD representation of Vx in memory locations I, I+1, and I+2
        public void execute(CPU cpu) {
            int position = cpu.getOpCode().getNibble(1);
            int data = cpu.getRegistry(position).get();
            int hundreds = (data - (data % 100)) / 100;
            int tens;

            data -= hundreds * 100;
            tens =  (data - (data % 10)) / 10;
            data -= tens * 10;
            cpu.getMemoryMap().getMemory(MemoryType.RAM).set(cpu.getRegisterI().get(), (byte)hundreds);
            cpu.getMemoryMap().getMemory(MemoryType.RAM).set(cpu.getRegisterI().get() + 1, (byte)tens);
            cpu.getMemoryMap().getMemory(MemoryType.RAM).set(cpu.getRegisterI().get() + 2, (byte)data);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x33;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Store registers V0 through Vx in memory starting at location I
            int index = cpu.getOpCode().getNibble(1);

            for(int i=0; i <= index; i++)
                cpu.getMemoryMap().getMemory(MemoryType.RAM).set(cpu.getRegisterI().get() + i, (byte)cpu.getRegistry(i).get());
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x55;
        }
    });

    instructions.add(new Instruction() {
        public void execute(CPU cpu) { //Read registers V0 through Vx from memory starting at location I
            int index = cpu.getOpCode().getNibble(1);

            for(int i=0; i <= index; i++)
                cpu.getRegistry(i).set(cpu.getMemoryMap().getMemory(MemoryType.RAM).get(cpu.getRegisterI().get() + i));
            cpu.getRegisterI().set(cpu.getRegisterI().get() + index + 1);
            cpu.getInstPointer().add(2);
        }
        public boolean validate(OpCode opCode) {
            return opCode.getNibble(0) == 0x0F && (opCode.get() & 0x00FF) == 0x65;
        }
    });
}

If you are storing your data in variables: 如果要将数据存储在变量中:

Method 1: 方法1:

make them final 使他们final

Example: public static final FieldType MYFIELD; 示例: public static final FieldType MYFIELD;

Method 2: 方法2:

you can make all your variables private and write the getters for them. 您可以将所有变量设为private并为它们编写getter。

Example 2: 范例2:

private static FieldType myField;
public static FieldType getMyField() {
    return myField;
}

Immutability is the key word you are looking for. 不变性是您要寻找的关键词。 Making your data container (Model) class immutable is always a good design 使数据容器(模型)类不可变始终是一个好的设计

Effective Java Item Item 15 covers this in depth. 有效的Java项目Item 15对此进行了深入介绍。

Yes, this is a common pratice in Java. 是的,这是Java中的常见用法。 Create a POJO class like this: 创建这样的POJO类:

public class Data {

    private String property1;

    public Data(String property1) {
        this.property1 = property1;
    }

    public String getProperty1() {
        return property1;
    }
}

To be completely honest, I am not entirely sure what you are trying to accomplish from the code that you posted. 老实说,我不太确定您要通过发布的代码来完成什么。 However, in response to your actual title, "How to make a read-only data Class in Java", you should look into Enumerations . 但是,根据您的实际标题“如何用Java制作只读数据类”,您应该查看Enumerations

Essentially Enums will give you the ability to create you data set once at compile time, and provide a bunch of helper methods to read the data you want. 本质上,Enums将使您能够在编译时一次创建数据集,并提供一堆帮助程序方法来读取所需的数据。

I am not entirely sure if it will help your use case, but it will definitely allow you to separate your data into a read-only style format. 我不确定它是否会帮助您的用例,但是绝对可以使您将数据分成只读样式格式。

I'm not sure if I'm reading you right, but it sounds to me like you're talking about defining a bunch of constants in your source. 我不确定我是否阅读正确,但这听起来像是您在谈论在源代码中定义一堆常量。 This is a mistake - data should not live in your source code. 这是一个错误-数据不应存在于源代码中。 It should live in data files. 它应该存在于数据文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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