473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

can an object find its parent?

Hi,

This is a strange question. Firstly, I'm working with custom classes,
nothing available in .net and I _don't_ want to add a parent property.
Here is the problem.

Lets say I have two classes.

public class1
{
public class2 Class2Instance = new class2();
}

public class2
{
public void somemethod()
{
****LOGIC HERE****
}
}

When an instance of class1 is created, it creates an instance of class2
inside it. How can class2 get a reference to its parent? Without having to
define a parent property? The code that goes in LOGIC HERE needs to talk to
the holding class ....

thanks!

C
Nov 16 '05 #1
4 1419
mdb
"ilPostino" <ne**@ip80.com> wrote in
news:eN**************@TK2MSFTNGP14.phx.gbl:
When an instance of class1 is created, it creates an instance of
class2 inside it. How can class2 get a reference to its parent?
Without having to define a parent property? The code that goes in
LOGIC HERE needs to talk to the holding class ....


Not that I know of...

Care to explain WHY you don't want a parent variable, so that we have some
understanding of your motivation for not wanting to do this??

-mdb
Nov 16 '05 #2
ilPostino,
I can think of 3 options:

1. Define a parent property.
2. Pass parent as a parameter to somemethod
3. Define class1 to be a singleton.

Most of the time I would find 1 or 2 to be the most appropriate.

Hope this helps
Jay

"ilPostino" <ne**@ip80.com> wrote in message
news:eN**************@TK2MSFTNGP14.phx.gbl...
Hi,

This is a strange question. Firstly, I'm working with custom classes,
nothing available in .net and I _don't_ want to add a parent property.
Here is the problem.

Lets say I have two classes.

public class1
{
public class2 Class2Instance = new class2();
}

public class2
{
public void somemethod()
{
****LOGIC HERE****
}
}

When an instance of class1 is created, it creates an instance of class2
inside it. How can class2 get a reference to its parent? Without having to
define a parent property? The code that goes in LOGIC HERE needs to talk
to the holding class ....

thanks!

C

Nov 16 '05 #3
I don't think what you describe is possible. There might be a
convoluted way to do it using reflection, but it seems quite unlikely.

Why are you so unwilling to store a reference to the parent in the
child?

P.
Nov 16 '05 #4
I didn't want a parent because I'm lazy and I'd have to pass that when
creating class2's ....

It may sound lame except I have an object structure nearing hundreds of
related objects. Having to always pass around parent information is a pain
but .... as I guessed I have no choice so have started work adding parent
properties...

thanks

-c
"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"ilPostino" <ne**@ip80.com> wrote in
news:eN**************@TK2MSFTNGP14.phx.gbl:
When an instance of class1 is created, it creates an instance of
class2 inside it. How can class2 get a reference to its parent?
Without having to define a parent property? The code that goes in
LOGIC HERE needs to talk to the holding class ....


Not that I know of...

Care to explain WHY you don't want a parent variable, so that we have some
understanding of your motivation for not wanting to do this??

-mdb

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
2
by: gsb | last post by:
I have an HTML page loaded into an iFrame contained in a DIV tag. From the loaded document how would I reference the DIV object? Thanks, gsb
12
by: marcadonis | last post by:
Hi! Does anybody know of a way that I can keep a reference to an object that I can then reuse? I tried various approaches using navigator, but these all fail in an iframe due to premission...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
4
by: jarek | last post by:
Hi, this is my code: CSSStyleDeclaration.prototype.__defineSetter__('display', displaySetter); function displaySetter(value) { var parent = findParent(document, this); if (parent) {
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
2
by: mars123 | last post by:
hi, I am facing a js error in my code, below is the prob. statement I have a radio2 javascript function as below, it works like this.. When a parent radio button is selected only one of its...
0
by: hott5hotj | last post by:
in Actionscript 3.0 Ive created a datagrid that populated with data. I want to create a pop up window to confirm whether the removal of an entry. When I call from the child object the following, I...
7
by: joproulx | last post by:
Hi, I was wondering if there was a way with Reflection to find dynamically if an object was referencing indirectly another object. A simple example would be: Object1 | --Object2 |
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.