Why do you want a global array? Global variables are error‑prone. Remember that arrays are always mutable; you can always sayJesse Matty wrote:. . . So how do I have a global array of player objects that any class can access?
I am 99% sure it didn't solve the problem. It probably added several new problems.Jesse Matty wrote:making the array static solved my problem
Jesse Matty wrote:what kind of problems could it have added?
Jesse Matty wrote:so even if I run two copies of the same program jar ( make a duplicate jar file using the os) file both will have the same player objects?
I wasn't intending on having more than one game being played at any point and time., or allowing anyone else to be able to that as it doesn't make much sense., or ever needing to make different game object.
Stephan van Hulst wrote:Classes that need information from the Game do so by interacting with the instance of the Game through methods defined in Game. They have access to the Game because you pass the Game to those classes in their constructors or methods. Don't interact with a class' fields directly, and don't extend a class just to get access to its members.
Let's say that you have some sort of user interface that needs to display information from the game. It can access the information like this:
If you make the array static, yes. At least within the same JVM.Jesse Matty wrote:so even if I run two copies of the same program jar . . . file both will have the same player objects ? . . .
Stephan van Hulst wrote:This will be easier if you can give an example of a class that needs access to a single player. We can then show you a small example of how it's done, without having to use global data.
If you want a job, don't let them see global variables.Jesse Matty wrote:. . . part a portfolio to help land me a job
Something which sends you on a wild goose chase.. . . what is a red herring . . .
No.Jesse Matty wrote:is this a an acceptable solution? . . .. . .
Stephan van Hulst wrote:Classes that need information from the Game do so by interacting with the instance of the Game through methods defined in Game. They have access to the Game because you pass the Game to those classes in their constructors or methods. Don't interact with a class' fields directly, and don't extend a class just to get access to its members.
Let's say that you have some sort of user interface that needs to display information from the game. It can access the information like this:
Jesse Matty wrote: I know what the applacation is supposed be about now I'm redoing parts of it because my design stank. I extended every class to some other class. I have written over 20,000 lines of code I'm re doing some of it; if I had to rewrite it all I would just make something else instead.
Stephan van Hulst wrote:Even if you need all those separate classes to access the different players, you don't need the players to be globally accessible to do it. Either you invert control, or you pass the player to a method of the class that needs to operate on a player.
However, look at these classes: LandSquare, Bazar, Tomb, Ruin, Tower... They look like places a Player can visit. If that doesn't scream visitor pattern, than I don't know what does.
Jesse Matty wrote:I got you on the visitable interface. But why another class to store player objects?
why to interfaces to go along with it?
Also what does T mean?