Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Factory Objects - practical application
Message
From
16/12/2006 17:15:01
 
 
To
15/12/2006 14:32:58
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01177742
Message ID:
01178308
Views:
27
I called it FactoryFactory, because
a) from outside it is a factory, in that concern you could also call it the/an abstract Factory.
b) all it really generates is oFactory, the real/normal/concrete factory.

I'm not thinking of THIS_Acess() to create a concrete Factory for every call, but that might even be an option, if oFactory is destroyed again after it has generated the object. Then I'd not do it with THIS_Access() but a normal method generating a factory, calling it then destroying it and passing back the returned object, which might be done in a chain of responsibility.

Concerning empty objects the caller should give some "instructions", what properties he wants. I like to use such objects based on empty as parameter or result objects passed in or out to/from functions/methods. I once posted the following CreateParameterOject Function, which could be some private method of a factory that could lookup the parameters with a class name/token from a factory table:
Local lo

? CreateParameterObject()

lo = CreateParameterObject("iX;iY")
? lo.iX, lo.iY

lo = CreateParameterObject("iX;iY","I;I")
? lo.iX, lo.iY

lo = CreateParameterObject("iX;iY","I;I","20;100")
? lo.iX, lo.iY

lo = CreateParameterObject("cFirstname;cLastname;dBirthdate","C;C;D","Olaf;Doschke;{^1968-12-28}")
? lo.cFirstname, lo.cLastname, lo.dBirthdate

lo = CreateParameterObject("iMembers;cType","I;E","AMembers(laDummy,loObject);Type('loObject.cType')")
? lo.iMembers, lo.cType

Function CreateParameterObject()
  Lparameters tcProperties, tcTypes, tcValues
  Local loObject
  loObject = Createobject("empty")

  Local lnCount, lnCounter
  Local Array laProperties[1], laTypes[1], laValues[1]
  Do Case
     Case Pcount() = 0
     Case Pcount() = 1
        * just add properties and leave them uninitialised
        For lnCount = 1 To Alines(laProperties,tcProperties,2,";")
           AddProperty(loObject,laProperties[lnCount])
        Endfor
     Case Pcount() = 2
        * add properties with default values in their variable type
        lnCounter = Alines(laProperties,tcProperties,2,";")
        If Alines(laTypes,tcTypes,0,";") # lnCounter
           loObject =.Null.
        Else
           For lnCount = 1 To lnCounter
              lcType = laTypes[lnCount]
              AddProperty(loObject;
                 ,laProperties[lnCount];
                 ,Icase(lcType="C","";
                       ,lcType="I",0;
                       ,lcType="N",0.0;
                       ,lcType="D",{};
                       ,lcType="Y",$0.0;
                       ,lcType="L",.F.;
                       ,lcType="T",{..::};
                       ,.Null.;
                       );
                 )
           Endfor
        Endif
     Case Pcount() = 3
        * add properties with passed in values in their variable type
        lnCounter = Alines(laProperties,tcProperties,2,";")
        If Alines(laTypes ,tcTypes ,0,";") # lnCounter Or;
              ALines(laValues,tcValues,0,";") # lnCounter
           loObject =.Null.
        Else
           For lnCount = 1 To lnCounter
              lcType  = laTypes[lnCount]
              lcValue = laValues[lnCount]
              AddProperty(loObject;
                 ,laProperties[lnCount];
                 ,Iif(lcType="C",lcValue,Evaluate(lcValue));
                 )
           Endfor
        Endif
  Endcase
  Return loObject
Endfunc
Bye, Olaf.
Previous
Reply
Map
View

Click here to load this message in the networking platform