Hey, I have two packages: one related to everything about the map and the other related to the character in a game. They don't have any relation, but in my Map package, I need the character's position to know where it is and be able to move it.
Should I create a variable in the MyMap class or in the MyCharacter class and import it into MyMap?
#is importing a lot of packages a good practice in OOP?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
It's a bit of an abstract question, dependant on the case you might be able to pass it in to relevant functions. As to the question, imports themselves don't have to be bad, it just depends on what these imports imply coupling wise.
And imports don't actually load/include anything. They just provide you with a shorthand to access the types. In general you should only import what you need though. Wildcard imports - import foo.bar.* can break in the future if that package adds a type-name that collides with something you're using.
where you create the variable depends on how cohesive it is to the type. if its the character's position, you can either have the map reference the character & use their position
or you could pass the coordinates to the map, where character & map each maintain their own set of coordinates, without map knowing of character
okay thx guys