On Friday, March 23, 2018 at 8:39:52 AM UTC-7, HiPhish wrote: 
>
> I might reconsider the rentals part, but that's not relevant at the 
> moment. My
> problem is that even though the three panes don't need to know anything 
> about
> each other, they need to know about their parent (the main tab view), I 
> cannot
> split the code into a module hierarchy like the tree.
>
>   (define main-window (new frame% [label "Library"]))
>   (define main-tab-view (new tab-panel% [parent main-window]))
>
>   (define books-panel (new vertical-panel% [parent main-tab-view]))
>   (define books-table (new list-view% [parent books-pane]))
>   (define books-buttons-pane (new horizontal-pane% [parent books-panel]))
>   (define add-button (new button% [parent books-buttons-pane]))
>   (define remove-button (new button% [parent books-buttons-pane]))
>   (define rent-button (new button% [parent books-buttons-pane]))
>
>
> And so on. This isn't much code, but add in all the callbacks and events, 
> and
> repeat that for all the three views, and the code quickly starts adding up.
> How should I break it up into smaller modules?
>

What about defining functions that accept the parent as an argument? That's 
essentially what creating a subclass with an init parameter does, but in a 
less roundabout way:

  (define main-window (new frame% [label "Library"]))
  (define (main-tab-view p) (new tab-panel% [parent p]))
  (define (books-panel p) (new vertical-panel% [parent p]))
  (define (books-table p) (new list-view% [parent p]))
  (define (books-buttons-pane p) (new horizontal-pane% [parent p]))
  (define (add-button p) (new button% [parent p]))
  (define (remove-button p) (new button% [parent p]))
  (define (rent-button p) (new button% [parent p]))

This assumes that the only thing tying these objects together is the 
parent-child relationship. If you've got more cross-component references 
then subclasses might be more manageable. Disclaimer: I'm not very familiar 
with Racket's class system or its GUI system, as I don't typically use 
either in my projects.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to