Re: Has anyone ever implemented a Decorator pattern in VB?

From: Mike D Sutton (EDais_at_mvps.org)
Date: 12/17/04


Date: Fri, 17 Dec 2004 17:42:38 -0000


> Class Factories? *scurries off to the VB help*
>
> What I have is, for every Singleton that I need, I have a module with a
> public method that returns an instance that implements the expected
> Interface class.
<code snipped>
> That's obviously simplified, but it sums up the gist of what I'm doing
> with my Singletons.

Class factories generalise this idea by having a single object whose sole responsibility it is to create other objects. This means
that you don't have to keep track of each singleton class, but let the class factory do this for you allowing you to simply ask the
factory for an object and it will do the work of checking to see if one exists and creating one where necessary. The only downside
of this method is that you have to register each class that the factory/ies can create at runtime, however in doing so it also
provides other benefits such as allowing for the use of constructors when creating objects from factories that create similar
objects.
When the objects are created they can also be given a pointer back to the factory that created them so that should the object be
required to instantiate other objects, it can use it's parent factory to do so.
Whilst you wont find anything in the VB help about class factories, there is an article on the MSDN about the design pattern here:
http://msdn.microsoft.com/library/en-us/dnbda/html/factopattern.asp
Of course the best reference on this is GoF's "Design Patterns"
If you (or anyone else following this thread) wants a basic VB implementation of class factories then I've written something up
which you may be interested in.
Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: http://EDais.mvps.org/



Relevant Pages

  • Re: Singletons
    ... when those conditions prevail Singleton is usually the best ... Like Abstract Factories implementations, Object ... WindowManager, so if WindowManager is a Singleton there is only one ... orthogonal to the number of instances of the leaf subclasses. ...
    (comp.object)
  • Re: Has anyone ever implemented a Decorator pattern in VB?
    ... > Class factories avoid use of global variables and make implementing ... What I have is, for every Singleton that I need, I have a module with a ... public function RemoteConnection() as iConnectionObject ...
    (microsoft.public.vb.general.discussion)
  • Is a static method sufficient to call it factory?
    ... Talking about factories why someone propose the way ... why the singleton? ...
    (comp.lang.java.programmer)