Organizing classes inside the component

Hi, before this project I used to have my extension code in one giant class. Sometimes it was 500-600+ lines of code. Now I’m diving more deeply into object oriented design patterns and following them trying to make my components have many small classes instead of one giant one.

My question is, how to do it in TD? Here’s what I’ve tried so far:

  1. Create 10 extensions for my component. First of all: after 3-rd extension it started to take significant amount of time for TD to re init all extensions. Second: I don’t see a point for having all my classes as extensions since I only want to interface with single “main” class.

  2. Have my “main” class as extension of the component and all my other classes just sitting in regular text DAT’s. Then in main I’d init them as mod('UtilClass').UtilClass(me) I really liked this approach until I realized that once I create an instance via import mechanism it gets cached and any changes to the child class doesn’t affect anything unless I reopen TD or do something else as radical as that

  3. Looked at TD components in pallete. There I saw that each sublass usually is an extension of a sub base with a little network inside. However, in my case all the work is done inside the class itself, so I don’t see a point in creating multiple base comps just to separate my extensions

Help please

TLDR: The best way is to use subcomponents with their own extensions. This makes it very convinient to transport and reuse the code in other components. Trying to modularize everything as much as possible.

1 and 2 are definitly possible but both sport the same issue. Changing one class forces all the other clases to reinit too.

The only “solution” I currently found to it is to init the Member as a None first and set the member to an instance of my class. But this results in the “caching” you described. But this can be undone by simply using a datExecute to watch the subclassText and force a run() method once to init the new instance without forcing an init on the other subclasses. But in this situation you can also just use subComps.

2 Likes

Thanks a lot for your answer! I guess I’ll stick with the subcomponents with own extensions solution. I think if I’ll be able to code them clever enough I really be able painlessly transfer them to my other projects in the future

Also, you could easily create a default Component that has the extensionDAT as the OPViewer in the base and map the edit pulse parameter to a customComponent to get quick acces :slight_smile:

1 Like