I am writing a communication software that will talk to lab processes in the control department in my uni. The processes communicate over serial port and there will be a fair bit of bit checking/manipulation. I have written a helper class like the following:
public class Channel {
public enum Kind {DIGITAL_IN, DIGITAL_OUT, ANALOG_IN, ANALOG_OUT, COUNTER_IN};
private int resolution;
private int number;
private Kind kind;
public byte[] bits;
public Channel(Kind kind, int resolution, int number) throws Exception {
if (resolution % 8 != 0) {
throw new Exception("Resolution must be divisible by 8");
}
this.kind = kind;
this.resolution = resolution;
this.number = number;
this.bits = new byte[resolution/8];
}
public int getResolution() {
return resolution;
}
public int getNumber() {
return number;
}
public Kind getKind() {
return kind;
}
}
My question now is if it would be considered bad practice in this case to have my byte[] declared as public? In my LabProcessProtocol class I will access these channels bits and change them according to what I get from the process on the serial port.
I have a hunch that Java is all about being private and using getters and setters but I'm not sure. It seems so convoluted in this case.
Thanks in advance.