BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parent-child relationship

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Tomaz Koritnik
Guest





PostPosted: Sat Oct 01, 2005 1:28 pm    Post subject: Parent-child relationship Reply with quote



I'm working on a vector graphics library and each graphical object can have
child objects. It's like windows in Windows where one is a parent to another
and there are infite amount of levels in a tree structure. Curently I'm
trying to choose between two models and I can't really decide which one to
choose:

Model 1: Delphi VCL style. Each object has it's parent and owner. Object is
placed on top of parent when displaying it and therefore parent-child
relationship only effects the visual representation. Owner however controls
object's lifetime and when owner is freed, object is freed also. If parent
is freed, object is not freed but only it's parent is cleared.

Model 2: Almost the same as model 1 but no owner this time. The parent
controls it's lifetime.

What do you think which model is better. I'm mostly thinking about model 2
because I's easyer and I haven't found enough reasons to go for model 1.

regards
Tomaz


Back to top
Efim Mett
Guest





PostPosted: Sat Oct 01, 2005 8:47 pm    Post subject: Re: Parent-child relationship Reply with quote



Hi

I think 2 things play role:

1. Whether some childs windows should live under some circumstances even if
their parent window has been destroyed. E.g. to be able to get some messages
from other windows or to retain their state.

2. Memory/Performance relationship. If you don't free childs together with
their parent, they preserve memory, but can be faster restored.

The both considerations are relevant to VCL as well.

/Efim

"Tomaz Koritnik" <nospam (AT) nospam (DOT) com> schrieb im Newsbeitrag
news:433e8e83$1 (AT) newsgroups (DOT) borland.com...
Quote:
I'm working on a vector graphics library and each graphical object can
have
child objects. It's like windows in Windows where one is a parent to
another
and there are infite amount of levels in a tree structure. Curently I'm
trying to choose between two models and I can't really decide which one to
choose:

Model 1: Delphi VCL style. Each object has it's parent and owner. Object
is
placed on top of parent when displaying it and therefore parent-child
relationship only effects the visual representation. Owner however
controls
object's lifetime and when owner is freed, object is freed also. If parent
is freed, object is not freed but only it's parent is cleared.

Model 2: Almost the same as model 1 but no owner this time. The parent
controls it's lifetime.

What do you think which model is better. I'm mostly thinking about model 2
because I's easyer and I haven't found enough reasons to go for model 1.

regards
Tomaz





Back to top
Bob Dawson
Guest





PostPosted: Sun Oct 02, 2005 2:05 am    Post subject: Re: Parent-child relationship Reply with quote



"Tomaz Koritnik" wrote
Quote:

What do you think which model is better. I'm mostly thinking about model 2
because I's easyer and I haven't found enough reasons to go for model 1.

Your sense that model 2 is 'default' and you need a justification for the
more complicated dual-hierarchy system is correct.

Delphi does some 'model flattening' to make RAD programming easier without
paying any attention to what the object visual relationships are. So a
button might be four or five hierarchial steps away from its form (parented
by panel on panel on tabsheet on page control on panel etc) with respect to
visual control, but it remains directly under the form from the messaging
and event perspective. That makes it easy to make all the components
interact--imagine having a button change the caption of a TLabel instance if
it had to walk two parent relationship trees in order to bring the label
into scope.

The dual system is a quite elegant solution for the problems being faced by
the VCL designers, but it's still a complication, and all complication must
be earned. If you don't see the need for it, don't do it.

bobD




Back to top
Tomaz Koritnik
Guest





PostPosted: Sun Oct 02, 2005 9:23 am    Post subject: Re: Parent-child relationship Reply with quote

Thanks both.

I made a decision and choose model 2. I don't have complication when
saving/loading objects and there is no complication when object are deleted.
One of non-selected objects could get deleted because it was owned by
deleting object and from the user point of view this must not happen.
Therefore a simple parent-child relationship has prevailed Smile.

regards
Tomaz


"Tomaz Koritnik" <nospam (AT) nospam (DOT) com> wrote

Quote:
I'm working on a vector graphics library and each graphical object can
have child objects. It's like windows in Windows where one is a parent to
another and there are infite amount of levels in a tree structure.
Curently I'm trying to choose between two models and I can't really decide
which one to choose:

Model 1: Delphi VCL style. Each object has it's parent and owner. Object
is placed on top of parent when displaying it and therefore parent-child
relationship only effects the visual representation. Owner however
controls object's lifetime and when owner is freed, object is freed also.
If parent is freed, object is not freed but only it's parent is cleared.

Model 2: Almost the same as model 1 but no owner this time. The parent
controls it's lifetime.

What do you think which model is better. I'm mostly thinking about model 2
because I's easyer and I haven't found enough reasons to go for model 1.

regards
Tomaz




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.