Hello, fellow programmers!
I have a question about organizing code into logical classes. I am aware of the OOP paradigm that classes should be as much as possible self-contained and self-sufficient. However, each time I am working on a program with more than 5000 lines of code I run into problems creating classes that fit these requirements. I end up with either a number of globally-accessible objects or a huge main class which contains many other classes. I either case they very closely interdependent.
Let me give you an example. Let's say that I am programming a game. Here is a structure I always end up with, and it feels horribly clumsy and incorrect (although it works perfectly fine):
- class Game is the "main" class, and will during whole running time have only one instance created of itself. It initializes instances following classes: TexturePool (loads textures), MissileEngine (handles collision and rendering of missiles), Level (contains level topology, objects, performs collision detection and more)
- The problem here is that all of the aforementioned classes have only one instance during runtime, which makes me feel that OOP is out of place here. Also, TexturePool and MissileEngine need to be available globally since classes GameObject and Player (inherits GameObject) need these to load textures and shoot missiles, respectively. Furthermore, MissileEngine needs access to TexturePool to load missile textures.
- As you see, there is a huge interdependence between classes.
This was just an abridged version of the source code structure, however I hope you understand where I am going with this. Since I have no formal education in programming, I am not sure this is the way it is supposed to be.
If you have any suggestions for me, I will be more than glad to hear them! The same applies for any books on the subject you might recommend.
Thanks in advance!