Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

Article Preview


Buy Now

Print:
PDF:

Object-Oriented Thinking

Designing a Server Class

The Facade and Mediator Patterns In Action

Issue: 4.6 (July/August 2006)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 5,331
Starting Page Number: 37
RBD Number: 4614
Resource File(s):

Download Icon 4614.sit Updated: Sunday, July 16, 2006 at 9:38 AM
Download Icon 4614.zip Updated: Sunday, July 16, 2006 at 9:38 AM

Related Web Link(s):

http://www.declareSub.com/

Known Limitations: None

Excerpt of article text...

I needed to implement a server as part of an application. In the initial version, I dropped a ServerSocket and an EasyTCPSocket onto a window, made the EasyTCPSocket into a control array, and implemented the events. I then wanted to replace the window with a Server class. But only in a Window can you implement events of other objects. I wanted to keep this capability in order to avoid a tangled mess of event-handling, but I didn't want to misuse a window to do so. Also, I wanted Server to be a singleton object. Here's how I did it.

Let's begin with a subclass DelegatingServerSocket of ServerSocket. To it, we add a public property EventHandler as ServerSocketEventHandler. Because we do not know who will want to handle ServerSocket events, we make ServerSocketEventHandler a class interface. Give it the following methods.

Function AddSocket(s as ServerSocket) as TCPSocket

Sub Error(s as ServerSocket, code as

Integer)

Now we implement the ServerSocket event handlers to simply call these methods.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com