|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
How to pass on events in this setup?
I'm creating an IRC client as a schooltask and have most things working, the following is an except from the UML diagram for the program (I have left out the parts I deemed irrelevant for this question but I want to upload a more detailed diagram if that would make things clearer)
Code:
IrcClient
|
IrcNetwork
|
IrcServer
|
IrcChannel
In this the IrcClient is the Controller to which GUI clients attach, it also maintains a list of IrcNetworks. The IrcNetwork keeps a list of servers for a certain network and tries each one of them until it finds one it can connect to or until it runs out of servers. The IrcServer class keeps a list of channels the user has joined on that particular server and passes incoming messages for a certain channel to the appropriate IrcChannel object. Now I wondered how I would notify the client/ui that a channel has been joined, so the GUI can do what needs to be done to support this (eg, create a new channel window) and to notify the client/ui that a new message has been posted to a channel. I'm sorry if this is a dumb question, but I'm no experienced OO designer. Thanks in advance for any help you can provide. |
|
#2
|
|||||
|
|||||
|
If you have not done so already, familiarise yourself with Design Patterns - they are nuggets of OO design put into a standardised format so that they can be reused.
What you need is a classic design pattern called Observer. The IRCClient has a method called something like 'registerObserver' that the GUI controller can call to tell the IRCClient that it should be notified when an event occurs. This way the IRCClient does not need to know anything about the GUI, so the code is kept nicely decoupled. You will need to design the interface between the observer and observed, but that is not hard. Here is some (pseudo) code: python Code:
Dave |
|
#3
|
||||
|
||||
|
Hmm, maybe I was not clear enough, I need to propagate the channelMessageReceived event from the IrcServer class to the IrcClient class, who can then send it to the appropriate listeners after having stashed everything in a more UI-friendly format, the problem is that I'm not sure how I should propagate the event from the IrcServer class to the IrcClient class, and I'm not entirely sure Observer is the way to go in that instance as I'm still having the IrcNetwork class sitting in the middle fo those two, and each IrcNetwork can be connected to only one server at a time whereas the IrcClient can be connected to many networks.
I hope this makes things a little bit clearer ![]() Thanks in advance |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > How to pass on events in this setup? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|