Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Factory Objects - practical application
Message
From
14/12/2006 15:06:13
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
14/12/2006 15:01:54
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01177742
Message ID:
01177754
Views:
33
Hi Craig

Long time no see.

>My Factory object gets instantiated during application startup and is referenced in the application object. So, to create a new object, such as what you want:
>
>
>loSafety = goApp.oFactory.Instantiate("SetResetOnOff","SAFETY")

Doesn't that mean that loSafety will be in the datasession that was active at the time of the instantiation of oFactory?

I am looking for a single way which ensures everything instantiates in the current datasession.

I messed up below anyhow.

This
>>loSafety = oFactory.GetClassName("SetResetOnOff"),"SAFETY")

should be

>>loSafety = CreateObject(oFactory.GetClassName("SetResetOnOff"),"SAFETY")

>
>
>>Hey all
>>
>>Assuming we have a need to instantiate an object.
>>
>>SET CLASSLIB TO xxfwutil.vcx
>>loSafety = CreateObject("cusPushPopOnOff","SAFETY")
>>
>>This code is too tightly coupled to the class. If I subclass that class or rearrange the vcxs, I'm in for major reworking.
>>
>>A factory object is a solution.
>>
>>loSafety = CreateObject(oFactory.GetClassName("SetResetOnOff"),"SAFETY")
>>
>>First problem: oFactory must have been instantiated someplace, probably with a segment like:
>>
>>PUBLIC oFactory
>>set classlib to blah.vcx
>>oFactory = Createobject("myfactory")
>>
>>It seems preferable to have a single table for the factory.
>>
>>I suppose I have a few choices:
>>1 - If the application has a table, the factory class could be specified there.
>>
>>2 - I could have a UDF that instantiated the factory by looking in the same table. That seems like redundant code.
>>
>>3 - How about the factory object calls that same UDF?
>>
>>PUBLIC oFactory
>>oFactory = CreateObject(UDFGetClassName("Factory"))
>>.
>>.
>>.
>>loSafety = oFactory.GetClassName("SetResetOnOff"),"SAFETY")
>>
>>and inside GetClassName...
>>
>>lparameters tcClassName
>>lcClassName = UDFGetClassName(m.tcClassName)
>>
>>Any body see anything wrong with that?
>>
>>Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform