samedi 24 août 2019

How to instantiate one object to communicate with others?

This is quite a generic programming question, but if it makes any difference, I will be coding in JavaScript (nodejs).

I have 3 classes: HTTPServer, IRCBot, and Game. The Game class will change depending on which game is being played, but the other two classes will remain the same.

HTTPServer and IRCBot will always have the same functionality. The HTTPServer and IRCBot will send incoming requests/messages to the Game class, the Game class will handle the requests/messages according to whichever game it is, and then the Game class will use the HTTPServer/IRCBot class to send requests/messages back.

Basically, the communication will look as such:

HTTPServer <-> Game <-> IRCBot

How should I go about instantiating these classes as cleanly as possible? The HTTPServer just needs the instance of Game, Game needs the instances of both HTTPServer and IRCBot, and the IRCBot just needs the instance of Game.

Or is there a better way to accomplish this?

Aucun commentaire:

Enregistrer un commentaire