Reputation: 177
I am programming a game for android in framework called libgdx
(if that is of any importance).
So I have about 8 different classes and in each one I need to measure things relatively to screen size so I make variables width and height.
My question is:
Is it better (for performance) to initiate new width and height variables in every class or just make them in one class and call them from other classes every time I need them??
Upvotes: 0
Views: 74
Reputation: 138
It would be more efficient to use a single pair of height and width variables and access them elsewhere, as you're using less memory.
Upvotes: 1
Reputation: 2167
You could implement an abstract class and declare these variables accordingly. Then using a getter you could retrieve these values in the other class.
By employing an abstract class you would be able to maintain some sort of a default hight and width and override it whenever required.
Upvotes: 1