I am going to write a library to control a whole bunch of relays, and I am just trying to think conceptually right now.
Here are my design constraints:
- We have an exact number of relays that need to be controlled, and this number will never change (because once we build a board we will never add relays).
Here is my proposed architecture:
- Have a class that represents a relay.
- Each relay should have an
- Each relay should have a
- Have a class that represents the circuit board that will Open/Close all the relays.
- Have the class contain a bunch of public members (one for each of the fixed number of relays).
So, conceptually my implementation would look something like...
RelayBoard myRelayBoard = new RelayBoard(); // establish a connection with the board myRelayBoard.Connect(); // close a relay myRelayBoard.RelayFive.Close(); // open a relay myRelayBoard.RelayFive.Open(); // disconnect the board myRelayBoard.Disconnect();
I am debating whether I should actually be using encapsulation here. The following, are my reasons for not wanting to use encapsulation.
- I don't think so because there are a fixed number.
- I also don't think so because they don't contain any data, the relay class is just a means for controlling each one.
- Also, I would have to write methods
OpenRelay(5)... This means that the caller would have to worry about what the name of the relay is, and that just doesn't seem as concise.
My only question here is, should I use encapsulation and make the relays private instead? I would like answers to at minimum address the 3 concerns I have about using encapsulation.