Jump to content
  • Advertisement
Sign in to follow this  
adder_noir

Getting two classes to talk!

This topic is 3026 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

What's the best way? Normally I create an instance of both and then use one in a parameter within the other's function calls. Is there a better more sopihsticated way? I've heard of methods what are they? Thanks for any help offered ;o)

Share this post


Link to post
Share on other sites
Advertisement
Your current method is a perfectly valid way of doing it and if it is working for you, then theres no harm in continuing to use it.

It does of course add a dependency between the classes (that is, the first class needs to know everything about the second) which sometimes just isn't sensible or even possible. In those cases a common solution is a global event/messaging system. Implementing a simple one if you ever need to is fairly trivial and shouldn't give you any problems, searching the forums should give you a fair few different ideas, opinions and implementations for them.

Share this post


Link to post
Share on other sites
You can get quite creative here. A good place to start would be to read up on object-oriented design patterns. Visitor, Observer, Chain, Command and Interpreter all come to mind. Writing an event handler will be time well-spent, if you haven't already.

Share this post


Link to post
Share on other sites
Quote:
Original post by coderx75
You can get quite creative here. A good place to start would be to read up on object-oriented design patterns. Visitor, Observer, Chain, Command and Interpreter all come to mind. Writing an event handler will be time well-spent, if you haven't already.


Thank you very much I've rated you up!

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!