How to add a trait to a class from an external package?
I have a TCXTBSButton trait that I want to add to a couple of WA classes. Now, I do not want to touch the WA classes as it would mean that I have to maintain them on my own, which isn't good. So, how do I add a trait to a class without changing its code? Programmatically adding a trait to a class on package/configuration load. For methods, I can do a *myownpackage so that things will be saved there. But for traits, I do not know how. Help :-) Phil
On 27.10.2014, at 11:16, phil@highoctane.be wrote:
I have a TCXTBSButton trait that I want to add to a couple of WA classes.
Now, I do not want to touch the WA classes as it would mean that I have to maintain them on my own, which isn't good.
So, how do I add a trait to a class without changing its code? Programmatically adding a trait to a class on package/configuration load.
For methods, I can do a *myownpackage so that things will be saved there.
But for traits, I do not know how.
Help :-)
I donât think thereâs any other option than doing a postload and recompiling those classes. Obviously, the packages of those classes will become dirty.
Phil
On Mon, Oct 27, 2014 at 11:18 AM, Max Leske <maxleske@gmail.com> wrote:
On 27.10.2014, at 11:16, phil@highoctane.be wrote:
I have a TCXTBSButton trait that I want to add to a couple of WA classes.
Now, I do not want to touch the WA classes as it would mean that I have to maintain them on my own, which isn't good.
So, how do I add a trait to a class without changing its code? Programmatically adding a trait to a class on package/configuration load.
For methods, I can do a *myownpackage so that things will be saved there.
But for traits, I do not know how.
Help :-)
I donât think thereâs any other option than doing a postload and recompiling those classes. Obviously, the packages of those classes will become dirty.
Annoying. I do not want them dirty. In the meantime, I have subclassed the TagBrush I need and added the trait there. But that's a pain for all other features that do use the superclass as such. Phil
Phil
On 27.10.2014, at 11:27, phil@highoctane.be wrote:
On Mon, Oct 27, 2014 at 11:18 AM, Max Leske <maxleske@gmail.com <mailto:maxleske@gmail.com>> wrote:
On 27.10.2014, at 11:16, phil@highoctane.be <mailto:phil@highoctane.be> wrote:
I have a TCXTBSButton trait that I want to add to a couple of WA classes.
Now, I do not want to touch the WA classes as it would mean that I have to maintain them on my own, which isn't good.
So, how do I add a trait to a class without changing its code? Programmatically adding a trait to a class on package/configuration load.
For methods, I can do a *myownpackage so that things will be saved there.
But for traits, I do not know how.
Help :-)
I donât think thereâs any other option than doing a postload and recompiling those classes. Obviously, the packages of those classes will become dirty.
Annoying. I do not want them dirty.
In the meantime, I have subclassed the TagBrush I need and added the trait there. But that's a pain for all other features that do use the superclass as such.
Phil
If youâre adventurous you could maybe copy the methods from the trait to the classes and classify them as extensions of your package. Then at least only your package would be dirty⦠But yeah, not very nice...
Phil
By the way, this is an interesting conceptual question. Because couple of times Iâve encountered this problem that I had to extend different entities with the same methods, which results in duplication. Uko
On 27 Oct 2014, at 11:31, Max Leske <maxleske@gmail.com> wrote:
On 27.10.2014, at 11:27, phil@highoctane.be <mailto:phil@highoctane.be> wrote:
On Mon, Oct 27, 2014 at 11:18 AM, Max Leske <maxleske@gmail.com <mailto:maxleske@gmail.com>> wrote:
On 27.10.2014, at 11:16, phil@highoctane.be <mailto:phil@highoctane.be> wrote:
I have a TCXTBSButton trait that I want to add to a couple of WA classes.
Now, I do not want to touch the WA classes as it would mean that I have to maintain them on my own, which isn't good.
So, how do I add a trait to a class without changing its code? Programmatically adding a trait to a class on package/configuration load.
For methods, I can do a *myownpackage so that things will be saved there.
But for traits, I do not know how.
Help :-)
I donât think thereâs any other option than doing a postload and recompiling those classes. Obviously, the packages of those classes will become dirty.
Annoying. I do not want them dirty.
In the meantime, I have subclassed the TagBrush I need and added the trait there. But that's a pain for all other features that do use the superclass as such.
Phil
If youâre adventurous you could maybe copy the methods from the trait to the classes and classify them as extensions of your package. Then at least only your package would be dirtyâ¦
But yeah, not very nice...
Phil
Basically, plugging a trait in a class dynamically should be doable. Especially with our beloved platform that can ;-) Otherwise, this reduces their usefulness quite a lot for composing things cleanly. Hey, Javascript people can do these things. Admittedly, all is dirty all the time there .... :-p Phil â
I wonder how JavaScript guys manage which behavior comes from base and which from a mixin. :) I used ExtJS, and you could do extensive use of mixins, but once they were mixed, it's all the same piece of code. I started using Traits and then moved away back to good'ol subclassification and, in some cases, code duplication. Regards! Esteban A. Maringolo 2014-10-27 7:44 GMT-03:00 phil@highoctane.be <phil@highoctane.be>:
Basically, plugging a trait in a class dynamically should be doable. Especially with our beloved platform that can ;-)
Otherwise, this reduces their usefulness quite a lot for composing things cleanly.
Hey, Javascript people can do these things. Admittedly, all is dirty all the time there .... :-p
Phil
I've used the following approach for a couple methods I need in more than one place: - fileout the protocol from class A. - open filebrowser, find the fileout file. - search/replace in the bottom pane the class A by class B - fileIn Quick and works. Phil On Mon, Oct 27, 2014 at 1:49 PM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
I wonder how JavaScript guys manage which behavior comes from base and which from a mixin. :) I used ExtJS, and you could do extensive use of mixins, but once they were mixed, it's all the same piece of code.
I started using Traits and then moved away back to good'ol subclassification and, in some cases, code duplication.
Regards! Esteban A. Maringolo
2014-10-27 7:44 GMT-03:00 phil@highoctane.be <phil@highoctane.be>:
Basically, plugging a trait in a class dynamically should be doable. Especially with our beloved platform that can ;-)
Otherwise, this reduces their usefulness quite a lot for composing things cleanly.
Hey, Javascript people can do these things. Admittedly, all is dirty all the time there .... :-p
Phil
participants (4)
-
Esteban A. Maringolo -
Max Leske -
phil@highoctane.be -
Yuriy Tymchuk