Hi everybody,
I have a question, about proper object oriented design.
I have a class of Game. This Game class contains instance of class Grid. This Grid class have one instance of class Tile and Tile get an ArrayList with Units. Whole schema is like: Game -> Grid -> Tile -> ArrayList.
But now i´d like to create subclass of Unit (we could name it Wizard), which hurt (by chain lighting spell) three nearest Units. How to find this three nearest units? To do this, I have to break proper OOP and asign to the Wizard class reference to Grid instance (which could contain method “find three nearest enemies”). Or make Grid class Singleton. Or make some static methods. But it is still breaking proper OOP design. It really damages my brain. Could you help me please?
Thx a lot
Peter
You could make Wizard contain a Grid reference?
I´m feeling a little embarrassed. But, this solution dont break OOP standards? Cause Grid contains references to Units. And Units could still contain reference to Grid? It´s not look like composition.
Thx a lot for answer.
Not sure either but that’s how I do stuff most of the times. I wouldn’t stress it too much
I was wondering about it, cause one older developer told me, that I could have a problem with it in later development. But anyway, thanks one more time, I’ll try it as you said.
Peter
In your castSkill() (or whatever you call it) function you can pass the grid as an argument.
But sticking to a pattern ‘just because’ isn’t a good way to code. Pick the right techniques for the job. Usually the simplest code is the best.