473,387 Members | 1,575 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,387 software developers and data experts.

Child object calling dynamic-parent method

how to work out a design to enable a child object to call its
parent(creator/container) method/property?

Its easy to be done if the child can know/assume its parent, but in my
scenario, many different object can create the same child object,
means the child object's parent is dynamic.

Event is possible, but I need the process in synchornous, as event
process is in asyn.

Class Parent()
{
Child objChild;
Public CallMeBack() {}
}
Class Parent2()
{
Child objChild;
Public CallMeBack() {}
}
Class Parent3()
{
Child objChild;
Public CallMeBack() {}
}

Class Child()
{
? objParent;
objParent.CallMeBack();
}

I attempt to use typecasting and interface, but the Child must be
well-aware of the type of the parent berfore the typecasting.
Nov 15 '05 #1
2 4836
Kelmen,
Event is possible, but I need the process in synchornous, as event
process is in asyn.


No, event handlers are called synchronously by default.
I'd make the parent classes implement a common interface

interface IParent
{
void CallMeBack();
}

and then pass in a reference to it to the Child constructor.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
I'm very grateful for the helpful info. Indeed, I have tested the
approach using Interface, it works as expected.

My initial fauilure attempt with testing is because forget to
implement the interface to the parent class. Somehow the .NET IDE
compile it "successfully", so I thought the interface approach doesn't
work. Luckily I found the missed out declaration later. I thought of
using call-back approach, but the info and requirement even confuse me
much more.
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<O$**************@tk2msftngp13.phx.gbl>...
Kelmen,
Event is possible, but I need the process in synchornous, as event
process is in asyn.


No, event handlers are called synchronously by default.
I'd make the parent classes implement a common interface

interface IParent
{
void CallMeBack();
}

and then pass in a reference to it to the Child constructor.

Mattias

Nov 15 '05 #3

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

Similar topics

1
by: Mike S | last post by:
I have an application that suffers from my amateur coding inefficiencies, and I am trying to clean a few things up. I have an extremely database intensive object, which I have tried breaking into...
22
by: Peter Ammon | last post by:
A friend was asked "How many ways are there to create an object in C++?" in an interview. Apparently, the "right" answer was eleven. Does anyone know how the interviewer arrived at that number? ...
1
by: szabelin | last post by:
Hi there were a few postings earlier, including mine regarding this. It looks as if when a dynamic child control causes a postback, its handler never gets called, and the control is null. This...
4
by: Grant Harmeyer | last post by:
How would I set up an httpHandler so that it would only apply to certain child directories of the application? I.E: <httpHandlers> <add verb="*" path="/files/*/*/*/*.aspx"...
1
by: Steve Booth | last post by:
I have a web form containing a button that when selected adds a user control to a place holder. The user control contains a button. The first time the user control is added the contained button...
2
by: M B HONG 20 | last post by:
Hi all - I am working on a web application and have run into a problem. From a main window (Window1) I open a child window (Window2), and from that child window I open a grandchild window...
4
by: mwebel | last post by:
Hi, i have another problem: i have a container basis class and want to write a virtual "copyFrom()" function. Basically the child class should copy from another child class....
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

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.