B
Beth
Hello.
I had a class that worked, but I knew wasn't designed correctly from an OO
point of view, so I changed it so it was more like I thought it 'should' be,
and now it doesn't always work. Works most of the time, but not always.
At first, I had an object variable declared in a class, and everything
worked fine.
Then, I figured I should really have 2 classes- one wrapping the other. I
need my object in both classes, so I passed it as a parameter to the
constructor in the new class, and that changed the behavior of the object.
Ideally, I'd like to retain the instance of the object in the outer class
and refer to it in the inner class instead of passing it as a parameter, but
I'm not sure how to do that (refer to an object or property in the class
holding an instance of me.)
What I want to do is:
Friend class clsOuter
Private m_objShared as clsShared
Private m_objInner as clsInner
Friend sub init()
m_objShared = new clsShared
m_objInner = new clsInner
end sub
friend readonly property sharedObj() as clsShared
get
return m_objShared
end get
end property
end class
Friend class clsInner
Private m_objShared as clsShared
Friend sub new()
m_objShared = myParents.objShared
m_objShared.doMethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth
I had a class that worked, but I knew wasn't designed correctly from an OO
point of view, so I changed it so it was more like I thought it 'should' be,
and now it doesn't always work. Works most of the time, but not always.
At first, I had an object variable declared in a class, and everything
worked fine.
Then, I figured I should really have 2 classes- one wrapping the other. I
need my object in both classes, so I passed it as a parameter to the
constructor in the new class, and that changed the behavior of the object.
Ideally, I'd like to retain the instance of the object in the outer class
and refer to it in the inner class instead of passing it as a parameter, but
I'm not sure how to do that (refer to an object or property in the class
holding an instance of me.)
What I want to do is:
Friend class clsOuter
Private m_objShared as clsShared
Private m_objInner as clsInner
Friend sub init()
m_objShared = new clsShared
m_objInner = new clsInner
end sub
friend readonly property sharedObj() as clsShared
get
return m_objShared
end get
end property
end class
Friend class clsInner
Private m_objShared as clsShared
Friend sub new()
m_objShared = myParents.objShared
m_objShared.doMethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth