On Apr 23, 2006, at 2:10 PM, Marc Van Olmen wrote:

Am 23.04.2006 um 19:05 schrieb Marc Van Olmen:

Not familiar with Factory, any URL's where i can find more info about this,

http://en.wikipedia.org/wiki/Factory_method_pattern

Hans-Georg

Good Description, I wasn't familiar with term, anyway it seems I was doing currently with "select case..." is Factory pattern.

It is. For reasons of performance and code maintainability, you might move from a Select Case block to something fancier. For example, you could do something like the following. Define a class ObjectFactory with a method NewObject(className as String) as Variant. Inside the class, you have a private property CreatorMap as Dictionary. Then the function is implemented like so.

Function NewObject(className as String) as Variant
  If CreatorMap.HasKey(className) then
    dim creator as ObjectCreator = CreatorMap.value(className)
    Return objectCreator.NewObject
  Else
    Return nil
  End if
End Function

ObjectCreator is a class interface with a single method NewObject() as Variant. You implement this interface in classes like WidgetObjectCreator.

Function NewObject() as Variant
  Return new Widget
End Function

You populate the CreatorMap Dictionary above at some point before using the ObjectFactory.

One advantage of such an approach is that you can add or remove ObjectCreators without having to rewrite ObjectFactory code.

There are other ways to implement this pattern, depending on your needs. The addition of shared methods to REALbasic provides other options.

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to