C
C#2w ago
Tobeash

Creating a level class that holds all the data for the game, should the data be private?

Hello, I am currently questioning the idea of encapsulating the level class of my project. What I am thinking is that, the level class will store data for all other classes and methods to use so, it make sense to make the data as assecible as possible by making it public so any other class or method can just access it and modify it by using something like level.data1, level.data2 and so on. Am I thinking wrong about this? Is really the best decision to encapsulate the whole class and create endless getters and setters and other operations, seems like its just going to bloat the code up and make things less readable
3 Replies
greyfox
greyfox2w ago
it only needs to be public if you intend to access it from outside the assembly.
Tobeash
TobeashOP2w ago
okay my bad i was thinking of internal would you be so kind to answer the question im asking though, its more in terms of OOP theory in practice
greyfox
greyfox2w ago
Only expose that which you need to expose. Hard to know without knowing more. Quite often you end up making previously private functions public as you need to do things to them, it's not a big deal.
Want results from more Discord servers?
Add your server