Sign in to follow this  

Getting two classes to talk!

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

This topic is 2660 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this