Answered Want to do this OOP stuff properly - separate class for a list of com ports?

blinky

Member
Joined
Oct 21, 2020
Messages
7
Programming Experience
Beginner
Hi,

Pretty much new to programming and defiantly new to OOP, so go easy! Im writing a tiny Windows Form app that will be used to open and close my observatory roof. I have created a seperate class for my observatory object but I will be communicating with the actual roof through the serial/Com port (its an Arduino controller that will open/close the switches to open/close the roof). As such I want the user to be able to select the correct com port, this will be done via some form of chooser, either on the main form, or maybe from a menu item on the main form. I think I know how to enumerate a list of the available COM ports but Im wondering where I should do this? Should I create a new class, say ComPorts that returns a list of the com ports and use that to populate the menu item or is it just as easy/better to do this within the main form.cs code?

Hopefully the above is clear enough!
 
The Forms are for UI. They should only concern themselves with UI as it's single responsibility. The available COM ports is part of your data model. You should have a separate class that keeps track of the available ports and that will be it's single responsibility.
 
The Forms are for UI. They should only concern themselves with UI as it's single responsibility. The available COM ports is part of your data model. You should have a separate class that keeps track of the available ports and that will be it's single responsibility.
Great, thanks for the reply! Look out for many more questions to follow.....
 
Back
Top Bottom