Problem to organize my code in classes
Hi everyone,
I'm just confused about how to organize my code.
Basically I have a GUI and other methods to load/write data from/into files.
For now, I just have one BIG class with everything inside but of course I know it's not that good and I would like to dispatch my code into classes.
I thought about creating one general class and put the methods that load/write files in that class and create another class just for the GUI. But actually, there are variables that I need in the load/write methods AND in the GUI too.
So, should I create this extra class for the GUI and make it "extends" the general class (where the main is, and the load/write files methods are) ? I'm not sure about this "extends", I mean if it's the right choice for my situation.
Can someone help me please ?
Thank you for your help.
Re: Problem to organize my code in classes
Actually your idea of seperating your classes by GUI and general is correct. I would have the GUI class extend the general class. This just allows you to make changes to the GUI class without having severe errors or changes to the general class and vise versa.
Re: Problem to organize my code in classes
Its always good to sit down before actually writing the code and think about organization. How you do so is up to you, but its a good idea to try and do so with some concepts in mind, one of which is the concept of code re-use. Its nice to have implementations that can be separated into their own objects and potentially used in aanother project without the dependency of the current project. This is also where 'loose' implementations come into play such as using interfaces and abstract classes, where one class or function doesn't depend upon a defined single class but rather an 'empty' implementation, which facilitates code-reuse. As a more semi-concrete example, one could create a class that represents the file you wish to read/write. All you need to do is create an object of that class, then access the variables you wish