> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Phil M > Sent: Friday, August 25, 2006 12:30 PM > To: REALbasic NUG > Subject: Re: RB code Hacks > > On Aug 25, 2006, at 10:20 AM, Guyren Howe wrote: > > > Permit me to elaborate. A factory function is a good > solution to this, > > but it doesn't provide what the original person was > looking for, which > > is something more loosely coupled and easily extensible. > > But first-class classes, suitably designed, do. > > > > If classes were themselves objects, with constructors and able to > > support polymorphism (a "Shared Interface", meaning the > shared methods > > on the class allow the class to be treated as an instance > of a type), > > then in the class's constructor, it can register itself with the > > factory, installing itself into the dictionary you suggested, and > > manufactures instances of itself on request. Now, the > factory works as > > in your solution, but the code is more loosely > > coupled: you can add new classes, delete classes, > whatever, and you > > never have to change the factory. > > I really have not been following this thread very closely, > but has anyone considered Shared Methods? Instead of making > an object factory, why not make the object itself be > responsible for creating an instance of it's type? > > Something like: > > [Shared] Function Instance() As MyClass > Return New MyClass > End Function
That makes sense. What would be good is to have an interface, call it InstanceFromClassName, with two methods, Instance (as decribed above) and ClassName (as described earlier in thread -- it simply returns the name of the class). Then any class you want to be instantiable (that's probably not a word) just has to implement that interface and it can be registered with the factory (which presumably would store the registered InstanceFromClassName-implementing objects, i.e., the mini-factories, in a dictionary), using a Register(instance as InstanceFromClassName) method. _______________________________________________ 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>
