Solved

Collection Puzzle

Posted on 2002-03-26
5
139 Views
Last Modified: 2010-05-02
Consider..

Parent -> Children -> Child

I want to include the method 'ChangeParent' method in the Child object.  

This is primarly used when a Child object is created in isolation! eg...

Dim oChild as New Child
Call OChild.ChangeParent(NewParentId)

If the Child object was created as part of the above heirarchy ( Parent -> Children -> Child )... what is the best way of informing the Parent object that a Child object has fired this event???????

0
Comment
Question by:crystaltips
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
usually, I have the Parent object be responsible for creating ITS Own children objects, and then give the Child Object a SetAsParent method, which accepts a Parent Object as the argument (and then in the Parent, when the Child Object's SetParent method is called, pass the Reference Me (of the parent).)  

After all, in the world that the Parent-Child model is mimicing, don't REAL parents create their own children, and the Child then KNOWS what parent it belongs to.(Didn't YOUR parents "create" you, and thus didn't YOU know who your parents were?)  Children should NOT be create in a vacuum, whether that be in a program, or in the Human-world.

Arthur Wood
0
 

Author Comment

by:crystaltips
Comment Utility
Thanks for the insight Arthur!

In the same vein, can't a child decide to leave its parents?

Perhaps the Parent/Child analogy was misleading.

Consider..

God->Children->Child

God can manage children without the parents' knowledge.
God decides that a Child object shall have a new parent.

How do I inform an instantiated Parent object that it has lost a child?





0
 

Accepted Solution

by:
zafarbhat earned 50 total points
Comment Utility
One way can be that you remove the Child from the current parent's Children collection and then add it in specified parent's Children collection.

This will need to be done in the procedure ChangeParent(vv)

Zafar Iqbal
0
 
LVL 16

Expert Comment

by:twalgrave
Comment Utility
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- split points Arthur_Wood and zafarbhat
Please leave any comments here within the
next seven days.
0
 

Expert Comment

by:SpideyMod
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange


Arthur_Wood: points for you added to:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20463733.html
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now