So assume I have one class named “Program” which contains my whole program of which i will create only one instance.
Now this class contains a lot (half of the code) of, say, functionality for shopping (methods and such).
Is it OK to create a class named “ProgramWithoutShopping” with half of the code as stated above, and then put my shopping-related code in a class named “Program” extending “ProgramWithoutShopping”, without ever using ProgrammWithoutShopping in any other purpose?
My goal would be to have a better overview because of seperated functionality and smaller files.
Has someone an example of a big project which actually used this strategy?
PS: If you are about to write “Don’t use classes at all”, you may assume that my program is running in a framework which needs it to be a class.
What language are you using? C# has a partial keyword that would also work for this case without requiring two classes.
To answer your question, it is fairly standard to have base classes that don’t do anything directly, but are useful overall. Typically this is used to avoid code duplication, but that is not a strict requirement.
I would instead postulate, are 2 classes enough? If the vast majority of your code base is in one class, then you are creating a maintenance problem even with two classes.
Maybe you could instead split up your classes into finer ones. For instances, a typical OOP class set could look like this:
And those are just data objects, depending on your implementation you could probably also encapsulate some of your algorithms, like how to calculate a price (although that could live in Item in this case…)