This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lame objects question

 
Keenan Staffieri
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It makes me feel inferior to ask this, but I have a question about objects in classes. Well I am working with a canvas, and I decided that I want to make a seperate object to have contructors that keeps track of screenwidth ect.

like:




i constructed it in WorldGenerator (which contains my main class)



I can refer to the setting object anywhere i want in the world generator class. BUT i cant refer to the setting object in a different TileMap class, because it cant recognize symbol because i didnt construct the object in the TileMap class:



So i guess i pretty much messed up my design...
i also tryed using things like static and public, but it feels "wrong" and, it doesnt work anyway. I even tryed to extend the WorldGenerator class, but it causes compile errors with the paramaters in the TileMap constructors.
[ December 06, 2006: Message edited by: Keenan Staffieri ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference to ProgramSetting could either be another parameter of the TileMap constructor, or the TileMap class could have a "setProgramSetting(ProgramSetting)" setter that is invoked after a TileMap object is constructed.
 
Keenan Staffieri
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i never want to change the screenwidth ect, in tile map. i want to make it so i can use the 'setting' object in ANY class, but i guess my design is messed up since i am using the setting thingy in a class that shouldnt have to take screenwidth parameters in the constructor. any recommendations?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also make the ProgramSetting object in TileMap public and static, so that any class can get access to it without needing to have a reference to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic