Jump to content
  • Advertisement
Sign in to follow this  
DarkZlayer

Referencing Objects When Creating a New Object

This topic is 3667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm programming a game like Advance Wars so I have many different objects such as the camera, units, tiles, etc. A lot of the time I find I have to pass in a lot of the same parameters into methods of each object to do the "logic" of different objects. I was wondering, how bad of practice it is to just reference the objects in the constructor of each in order to avoid having to continuously pass in these parameters. I also ask because it feels like I am doing it incorrectly when I will call the draw method for my interface with a few things that, that methods doesn't use but rather a method it calls within itself (such as drawing a certain section of the GUI). If I'm not clear on what I mean just let me know. I am terrible with techincal names of things, but I think I used the correct terms.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by DarkZlayer
So I'm programming a game like Advance Wars so I hav
I also ask because it feels like I am doing it incorrectly when I will call the draw method for my interface with a few things that, that methods doesn't use but rather a method it calls within itself (such as drawing a certain section of the GUI).


Sometimes, that is an indication that you should reverse the calling order. Rather than have draw() call foo(), foo() should be calling draw.

You're not clear on responsibilities and dependencies, so your systems need to know more than necessary. There is no trivial answer, but it's a common problem when unfamiliar with a certain domain, when you don't know up-front what exactly you will need, or who is responsible for what.

This is sometimes a problem in A-uses-B-uses-C, where B is either redundant from functional perspective, and exists only because it seems it should due to OO design. Several solutions exist. One is have C depend on A: B-uses-C(A), the other is to reverse the order A-uses-C-uses-B.

Or many other options, cause of the problem is almost certainly incorrect abstractions of functionality or responsibilities.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!