Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass object to method NOT by reference
Message
De
13/07/2016 09:23:17
 
 
À
12/07/2016 17:03:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
Windows Server 2012 R2
Database:
Visual FoxPro
Application:
Desktop
Virtual environment:
VMWare
Divers
Thread ID:
01638158
Message ID:
01638320
Vues:
117
Personally I have concluded that parameter objects passing info across a normal program stack in the same process is often not a good approach, esp. if the need for cloning arises. If the code lives in one process, object oriented programs should call methods on the same object to for a task possibly broken into smaller subtasks. Methods should recurse to "this" properties plus traditional parameters as needed. Just another facet of "chunky, not chatty" organization principle. Objects given as parameters should expect to be worked upon, not needed to be cloned just to be "passable" again.

Going across network layers or other to another process the discoverability of (JSON/XML/COM) objects makes much more sense.

But that is highly debatable plus to be seen in the usage of the task.

If a couple of items like a hashmap have to be transferred/cloned across many stack levels in a vfp program and are not seeing heavy access on each item on each stack level of the parameter object, using a [n,2] array with column1 = name, column2 = value is in Vfp a way to create "parameter info" which is easy to copy wholesale via acopy(), ***relatively*** fast to access via taParameter[ascan(...), 2] and gives you an easy method signature (@taParameter) similar to (toParameter)

regds

thomas

PS
is that "a [n,2] array" or "an [n,2] array" ? Does the bracketed n count ? Did not want to weasel to "an array with [n,2]" ?

;-))



>This is not that big of an object (a couple to a few properties) so I can work around the problem now that I understand what is going on. Thanks to the others as well.
>
>Thanks,
>Albert
>
>>You ARE passing by value, but only the object handle (C pointer if you look at it from that perspective).
>>If you want to "isolate" the object (property values) passed down, you have to make a deep copy/clone, pass that - this will leave the original undisturbed.
>>NOT the way parameter objects typically work, so rethink your approach at least twice. Can result in multiplying the typical function call overhead (in vfp already relatively large compared to statically typed languages like Java, C# or C++). If you go that way, at LEAST create an object pool for the calling stack parameter objects. Did that once way back to salvage an overPOOPed parameter object passing fwk design already far overspending and missing the targeted speed by a lot ;-))
>>
>>
>>>Hi all,
>>>
>>>This should be fairly "basic" but have never figured it out...I know how to pass a variable or array to a function by reference (by prefacing with @) but in this case I want to pass an object to a method and force it to pass by "value" i.e. make a copy
>>>
>>>loSomeObject=CREATE("empty")
>>>ADDPROPERTY(loSomeObject,"FileName","C:\temp\test.doc")
>>>
>>>loFileWhizBang.OutputFile(loSomeObject)
>>>
>>>*** and method Outputfile ***
>>>
>>>LPARAMETERS toFileObject
>>>
>>>* strip the path off for some use
>>>toFileObject.FileName = JUSTFNAME(toFileObject.FileName)
>>>
>>>I *usually* load everything into local vars when doing things like this but trying to "tighten up" some code, I decided to do the alteration on the object property not realizing that it was not a LOCAL copy. So I instead tried to pass the object in a way that forces toFileObject to a local value. Could not figure and help files did not help.
>>>
>>>Any way to do it?
>>>
>>>Albert
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform