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.objSh ared
m_objShared.doM ethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth 4 1781
Your approach seems fine to me. If the class clsShared is truely a single
instance object, then another approach would be to follow the Singleton
class design pattern. You have not made it clear if that would work for you
or not though.
"Beth" <Be**@discussio ns.microsoft.co mwrote in message
news:26******** *************** ***********@mic rosoft.com...
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.objSh ared
m_objShared.doM ethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth
On 2008-10-15, Beth <Be**@discussio ns.microsoft.co mwrote:
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.objSh ared
m_objShared.doM ethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth
(Air Code)
Class Outer
Private _inner As InnerClass
Private _shared As SharedClass
Public Sub New()
_shared = new SharedClass()
_inner = new InnerClass (Me)
End Sub
Class Inner
Private _parent As Outer
Sub New (ByVal parent As Outer)
_parent = parent
_parent._shared .DoMethod()
End Sub
End Class
End Class
Anyway... something like that? Or do you need the shared instance accross
multiple instances of outer/inner. I'm a little unclear of what your trying
to accomplish.
--
Tom Shelton
It took me awhile to think of an example, but what I want is something like
the relationship between a form class and the application object.
The application object contains a collection of form objects, and yet within
a form class, you're able to reference the containing application object's
properties. There's also only one instance of the application object.
I'm not sure what a 'singleton' is, but I can look into that, too.
Thanks for the replies.
-Beth
"Tom Shelton" wrote:
On 2008-10-15, Beth <Be**@discussio ns.microsoft.co mwrote:
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.objSh ared
m_objShared.doM ethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth
(Air Code)
Class Outer
Private _inner As InnerClass
Private _shared As SharedClass
Public Sub New()
_shared = new SharedClass()
_inner = new InnerClass (Me)
End Sub
Class Inner
Private _parent As Outer
Sub New (ByVal parent As Outer)
_parent = parent
_parent._shared .DoMethod()
End Sub
End Class
End Class
Anyway... something like that? Or do you need the shared instance accross
multiple instances of outer/inner. I'm a little unclear of what your trying
to accomplish.
--
Tom Shelton
Here is a definition and example page for the singleton pattern. http://www.dofactory.com/Patterns/PatternSingleton.aspx
"Beth" <Be**@discussio ns.microsoft.co mwrote in message
news:96******** *************** ***********@mic rosoft.com...
It took me awhile to think of an example, but what I want is something
like
the relationship between a form class and the application object.
The application object contains a collection of form objects, and yet
within
a form class, you're able to reference the containing application object's
properties. There's also only one instance of the application object.
I'm not sure what a 'singleton' is, but I can look into that, too.
Thanks for the replies.
-Beth
"Tom Shelton" wrote:
>On 2008-10-15, Beth <Be**@discussio ns.microsoft.co mwrote:
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.objSh ared
m_objShared.doM ethod
Is there another way I'm supposed to share a single instance of a class
across multiple classes?
Thanks for the help,
-Beth
(Air Code)
Class Outer Private _inner As InnerClass Private _shared As SharedClass
Public Sub New() _shared = new SharedClass() _inner = new InnerClass (Me) End Sub Class Inner Private _parent As Outer
Sub New (ByVal parent As Outer) _parent = parent _parent._share d.DoMethod() End Sub End Class End Class
Anyway... something like that? Or do you need the shared instance accross multiple instances of outer/inner. I'm a little unclear of what your trying to accomplish.
-- Tom Shelton This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andy |
last post by:
Hi
Could someone clarify for me the method parameter passing
concept?
As I understand it, if you pass a variable without
the "ref" syntax then it gets passed as a copy.
If you pass a variable with the "ref" syntax then it gets
passed as a reference to the object and any changes to
|
by: Gregory Piñero |
last post by:
Hey guys, would someone mind giving me a quick rundown of how
references work in Python when passing arguments into functions? The
code below should highlight my specific confusion:
<code>
bool1=True
lst1=
def func1(arg1): arg1.append(4)
|
by: bob_jenkins |
last post by:
{
const void *p;
(void)memset((void *)p, ' ', (size_t)10);
}
Should this call to memset() be legal? Memset is of type
void *memset(void *, unsigned char, size_t)
Also, (void *) is the generic pointer type.
My real question is, is (void *) such a generic pointer type that it
|
by: Sahil Malik [MVP] |
last post by:
Okay so now I understand (surprised though) - that WebServices can indeed
pass ByRef/ref parameters. All I have to do is mark an integer parameter of
a WebMethod as "ref". Funnily enough, this is also supported per the SOAP
Spec, and from what I understand, .NET's implementation of WebServices,
donot follow the standard, but instead shimmy this behavior by working with
a strict request/response WSDL.
So my question is - If I mark an int...
|
by: John Pass |
last post by:
Hi,
In the attached example, I do understand that the references are not changed
if an array is passed by Val. What I do not understand is the result of line
99 (If one can find this by line number) which is the last line of the
following sub routine:
' procedure modifies elements of array and assigns
' new reference (note ByVal)
Sub FirstDouble(ByVal array As Integer())
Dim i As Integer
| |
by: Christopher Benson-Manica |
last post by:
Does the following program exhibit undefined behavior? Specifically,
does passing a struct by value cause undefined behavior if that struct
has as a member a pointer that has been passed to free()?
#include <stdlib.h>
struct stype
{
int *foo;
};
|
by: TS |
last post by:
I was under the assumption that if you pass an object as a param to a method
and inside that method this object is changed, the object will stay changed
when returned from the method because the object is a reference type?
my code is not proving that. I have a web project i created from a web
service that is my object:
public class ExcelService : SoapHttpClientProtocol
{
|
by: Jason |
last post by:
Hello
I've got a very simple C# app, that has a datagrid, a text box, and a button
which when clicked opens a second form...
Form2 frm2 = new Form2();
frm2.Show();
When I place a datagrid, onto form1 I point to a DB called Test DB and then
my text box, I modify the databinding property to my bindingSource which in
|
by: dave_dp |
last post by:
Hi, I have just started learning C++ language..
I've read much even tried to understand the way standard says but still
can't get the grasp of that concept.
When parameters are passed/returned by value temporaries are
created?(I'm not touching yet the cases where standard allows
optimizations from the side of implementations to avoid copying)
If so, please quote part of the standard that says that.
Assuming it is true, I can imagine two...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |