Special

Special Print Closeout!

We're clearing out the remainder of our print issues at fire sale prices -- as much as 75% off! Quantities are extremely limited and only available while supplies last. Hurry to take advantage of this one-time offer.

RBD Magazines

Once these printed back issues are gone, they are gone!

Article Preview


Buy Now

Print:
PDF:

Object-Oriented Thinking

Use Polymorphism to Simplify Code

Issue: 2.2 (October/November 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky
Article Description: No description available.
Article Length (in bytes): 4,807
Starting Page Number: 36
RBD Number: 2216
Resource File(s): None
Related Web Link(s):

http://www.refactoring.com/

Known Limitations: None

Excerpt of article text...

You're writing a widget server, and you'll want to implement logging. You'll want to offer several logging levels; let's say, Error, Warning, and Debug. You'll want to offer various output possibilities -- Console, log file, or no output for each logging level. Let's take a hypothetical look at how you might do that.

We'll start with a module Logger; I suggest a module because I expect that we'll want one instance only, and we'll want it always available.

Sub LogErrorMessage(message as String)

dim msgDate as Date

dim logMsg as String

msgDate = new Date

logMsg = msgDate.ShortDate + " " + msgDate.ShortTime + " " + "Error: " + message

If LogErrorsToConsole then

TellConsole logMsg

ElseIf LogErrorsToFile then

AppendToFile logMsg

Else

//don't log these messages

End if

End Sub

TellConsole and AppendToFile are protected subroutines that do what their names suggest. LogErrorsToConsole and LogErrorsToFile are Boolean constants set in a preferences window somewhere.

...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