Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2005, 05:44 AM
theBlackDragon's Avatar
theBlackDragon theBlackDragon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Zomergem (Belgium)
Posts: 145 theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2139 Folding Title: Novice Folder
Time spent in forums: 1 Day 17 h 14 m 38 sec
Reputation Power: 16
Send a message via ICQ to theBlackDragon Send a message via AIM to theBlackDragon Send a message via Yahoo to theBlackDragon
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.

Reply With Quote
  #2  
Old November 6th, 2005, 03:45 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 10 m 34 sec
Reputation Power: 265
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:
Original - python Code
  1. class IRCClient:
  2.     def __init__(self):
  3.         self.observers = []
  4.  
  5.     def registerObserver(observer):
  6.         self.observers.append(observer)
  7.  
  8.     def joinChannel(...):
  9.         ... do stuff for joining a new channel
  10.         for observer in self.observers():
  11.             observer.observeJoinedChannel(channelInfo)


Dave

Reply With Quote
  #3  
Old November 7th, 2005, 04:08 PM
theBlackDragon's Avatar
theBlackDragon theBlackDragon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Zomergem (Belgium)
Posts: 145 theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)theBlackDragon User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2139 Folding Title: Novice Folder
Time spent in forums: 1 Day 17 h 14 m 38 sec
Reputation Power: 16
Send a message via ICQ to theBlackDragon Send a message via AIM to theBlackDragon Send a message via Yahoo to theBlackDragon
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > How to pass on events in this setup?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT