The C # project that I used to teach code so far has been one gigantic form containing many functions and a huge number of "global" static variables.
Having read here, having done some lessons, etc., now I am trying to go through the refactoring process in order to use classes and encapsulation correctly.
My classes:
Program.cs - in principle, does nothing but initialize Form1 .Form1.cs = Creates and modifies the entire user interface. It calls public functions in other classes and has some public functions that other classes can call to update it.UiStrings.cs = Contains all error messages, dialogs, instructions, etc.Options.cs = Monitors some settings, builds and updates paths for installing files, and executes code based on changing the interface.Updater.cs = monitors the current version, downloads assets, puts them in the right place and adjusts the settings.Installer.cs = handles installation / deletion / backup of all assets based on current parameters.
First, I instantiated each of my other classes in Form1 . This worked for Form1 to be able to access functions and properties in UiStrings or Options . However, these classes could not access each other, apparently because they were not created.
What this led me to applies to all of my custom classes, such as UiStrings and Options static (since I don't need multiple instances of any of them). It also means that I have to make every function and property inside each of these classes static too.
Is it a smart decision that someone who really knows what they are doing will come?
It seems that I have worked in my testing so far, but my initial attempt without any classes generally worked very well until I found out how it was wrong.
source share