# Why does the derived class instance need to be duplicated wi

**URL:** <https://www.ruby-forum.com/t/why-does-the-derived-class-instance-need-to-be-duplicated-wi/67260>\
**Category:** Ruby\
**Created:** [September 1, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/why-does-the-derived-class-instance-need-to-be-duplicated-wi/67260 "2006-09-01T18:02:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lionel\_MAIAUX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lionel\_MAIAUX](https://www.ruby-forum.com/u/Lionel_MAIAUX)\
**Post date:** [September 1, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/why-does-the-derived-class-instance-need-to-be-duplicated-wi/67260/1 "2006-09-01T18:02:50Z")

</div>

Hello,

Is there any reason to duplicate the derived class instance when using  
TkComposite ?

Examples :

1/ tk/sample/scrollframe : there are 3 frames instantiated for a  
Tk::ScrollFrame object : self (derived from TkFrame), @frame (from  
TkComposite) and@base (embedded frame)  
Why can’t we use self for the enbedded frame ?

2/ tk/sample/tktextframe.rb : there are 2 TkText instantiated for a  
TkTextFrame object : self (derived from TkText) and @text.  
Why this duplication ?

Thanks for your explanations and regards,  
Lionel

---

<div class="post-metadata">

**Author:** ![Lionel\_MAIAUX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lionel\_MAIAUX](https://www.ruby-forum.com/u/Lionel_MAIAUX)\
**Post date:** [September 5, 2006, 6:53am UTC](https://www.ruby-forum.com/t/why-does-the-derived-class-instance-need-to-be-duplicated-wi/67260/2 "2006-09-05T06:53:10Z")

</div>

From: Lionel MAIAUX [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Why does the derived class instance need to be duplicated with  
TkComposite  
Date: Sat, 2 Sep 2006 00:32:16 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Is there any reason to duplicate the derived class instance when using  
> TkComposite ?

TkComposite is used to create a Mega-widget class which is constructed  
with some widgets on one frame (a base frame).  
The module overrides “initialize” method.  
The new “initialize” creates a new base frame (set it to @frame) and  
call “initialize\_composite” method (anticipates “initialize\_composite”  
constructs all part of the mega-widget).

Please imagine a mega-widget which is a text widget with some  
decoration.  
Then, because your mega-widget should have properties of a text  
widget, you will inherit TkText class for your mega-widget class.  
However, TkComposite#initialize doesn’t create a TkText widget.  
You must construct a text widget and other widgets (to decorate the  
text widget) on one base frame widget to treat it as one component  
(You must do that in “initialize\_composite” mehtod).

Now, all method calls about geometry management (pack, grid, and so  
on) must be sent to the base frame, and all methods to control the  
text must be sent to the text widget.  
@epath and @path instance variables are used for this purpose.  
@epath keeps the widget path of the base frame, and @path keeps the  
widget path of the text widget.  
Methods about geometry management refer @epath, and other methods  
refer @path. That is the reason of why inherited methods can be sent  
to the proper widget. And, I think, it will be an answer to your  
question.
