Sharing Instantiated Object
PropNewbie
Posts: 10
If I define an object in the OBJ block is it possible to share the same instance of that object with other objects? The reason I ask is that I have written some debug code (in·a UTIL object) that tips·text out to a VGA display. I would like to be able to instantiate a UTIL object and make a reference to it available in·multiple other·objects. It is not possible to have two UTIL objects·started as they·would each take a cog·and collide on the VGA output pins.
The scenario I wish to achive (in·pseudo code - I know this code is not valid) is
### Main·Object
OBJ
·· util = "utils"
·· wObj = "worker"
PUB·Main
·· utils.Init
·· utils.DebugOut(string(Main Initialized),CR)·
·· wObj.Init(@util)
###·Worker·Object
·
OBJ
·· util = null
·
PUB·Init(utilObj)
·· utils := utilObj
·· utils.DebugOut(string(Worker Initialized),CR)··
The idea is to have a kind of base utility class I can reference in various spin objects and make a standardized intialization convention. Is this possible? If I just do a·util = "utils"·in the worker object OBJ block·I get an "illegal circular reference" message.
Is it possible to do what I have just described or is it simply too high level a concept?
The scenario I wish to achive (in·pseudo code - I know this code is not valid) is
### Main·Object
OBJ
·· util = "utils"
·· wObj = "worker"
PUB·Main
·· utils.Init
·· utils.DebugOut(string(Main Initialized),CR)·
·· wObj.Init(@util)
###·Worker·Object
·
OBJ
·· util = null
·
PUB·Init(utilObj)
·· utils := utilObj
·· utils.DebugOut(string(Worker Initialized),CR)··
The idea is to have a kind of base utility class I can reference in various spin objects and make a standardized intialization convention. Is this possible? If I just do a·util = "utils"·in the worker object OBJ block·I get an "illegal circular reference" message.
Is it possible to do what I have just described or is it simply too high level a concept?
Comments
Then write wrapper functions in Worker for those routines you need to use in Utils. Say there is a method in Utils call get_parameters(return_ptr) that you want to use in Main, you can write the following routine in Worker:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
As a suggestion, why not implement a GLOBALOBJ directive in the propeller tool. It would work similarly to OBJ but an object defined there would only get one instance irregardless of how many other objects defined it. All would reference the one instance.
Just a thought....
Everything in the DAT section is global to every instance of the object so just put your variables there instead of in VAR.
What I'm trying to say is that GOBALOBJ isn't actually needed, there are facilities at your disposal to implement the same objective.
OO = Object Oriented
OOL = Object Oriented Language
BTW I too have wished at times to be able to circumvent the strong encapsulation, such as trying to display data to a TV_text object from multiple objects, but with a little effort I got it to work the way I needed it to.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 5/22/2008 1:55:02 AM GMT
Paul, next time just bring up politics. Or religion.
BTW I cut the most incendiary passages out of the the previous post, I don't have time to engage in a detailed·OOP debate. One of these days I'll learn how to respond to a prickly question without opening a can of worms, but perhaps all I can do is aspire to that goal.
I would rather see some form of inherency implemented since that is a OO accepted way of dealing wth this issue.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 5/22/2008 4:05:18 PM GMT