Mainly a subjective question (a bit similar to my previous thread)
Let’s say that I have a 2 classes : Player and Background. (it’s just an example, I don’t have them that way)
Eventually, I’ll have to render them on the screen so they will, at least, both have :
- int x, int y, int w, int h (position) (or a vector, doesn’t matter)
- float a, float r, float g, float b (color)
- more things (…)
There are lots of way to solve this, but what would be your approach? Make an intermediate class that will hold the values? Extend it? Integrate it as a parameter in both classes? Or simply copy’n’paste all those type of variables in all classes?
Even tough it’s supposed to be good practice to avoid redundant code mostly for performance and/or evolution issues, we’re just talking about int & float in modern applications here so does it really matter?
Besides not using an intermediate object makes it easier to access the value from an instance: pl.getX() instead of pl.getPosition().getX() for example. Using intermediate objects for redundant values seems the good way, but somehow when you start to have lots of classes, you just end up calling an intermediate value from another intermediate object from another intermediate object again.
One other thing, are you using interfaces a lot to implement common methods? What I mean by that is, most of the time, I find it easier to just make a Factory/Builder or whatever “Checker” class with statics methods to do the job. I don’t know, for some reason I just enjoy making a pattern where I have ONLY values left, and ONLY methods right, not both in the same class, but is this really a good thing?
For example, instead of implementing an interface that would make my Player class have an “update” method, I’d just create an Updater static class (which will virtually be able to manage all kind of ‘updates’ needed for the game) that will make different things depending on the method I’m calling and with what parameters, like for the print :
- public void update(Player player)
- public void update(Background background)
I just don’t like to have that “@override” method in my Player class, I’d rather have it hold important values only.
Oh and on a side note : HOW THE HELL ARE YOU PROGRESSING IN YOUR PROJECTS?
Most of the time, I just take too damn much time thinking of things like the ones mentioned in this thread, even though I know it’s a bad thing, but I can’t stop >:(
I seriously need to kill that part of my brain…