Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CreateObject() vs NewObject()
Message
From
22/08/2007 14:33:49
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
CreateObject() vs NewObject()
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01249678
Message ID:
01249678
Views:
103
Attempting to make a (sort of) final list of pros and cons for both approaches:

CreateObject() with Set Classlib + Set Procedure
Pro:
- you only need the name of the class and don't care where is it defined
- you don't need to specify any extra parameters when creating it
- if you move a class (from prg to vcx, vcx to prg, vcx to vcx, prg to prg), the createobject() commands don't need to be touched at all
Con:
- you need to maintain the Set Classlib + Set Procedure lists (can be automated, I did that)
- when something goes wrong, you have no clue where the class is defined, unless you got a good output from aStack(); if no error but still need to fix something, only Code References can help you

Newobject() with 2nd parameter
pro:
- no need to maintain Set Classlib + Set Procedure lists
- you can have a class with the same name in a different location and still instantiate it (not that anyone sane would do that)
- when you read code, the location of the classlib is obvious
con:
- you must know where your class is
- if you move a class, all the newobject() calls need to be edited (or you should use a factory)
- you must specify the extra parameters in newobject()

I have probably forgot some... so add.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Next
Reply
Map
View

Click here to load this message in the networking platform