Style Advice

I would appreciate any thoughts concerning the best style to use in the following situation.

I acknowledge that some do it one way, while others do it another. I am looking for thoughts regarding what is the “best,” and most practical method with AppleScriptObjective. I am still fighting the temptation to write in a more linear fashion. The examples I use here are completely made up.

Let us suppose, as examples, that we have two different menus. Each menu opens up a separate window. In Window 1, the user enters two numbers, presses “OK”, and gets the sum of the two numbers. Easy enough.

Suppose Window 2 does a different calculation. Suppose Window 2 calculates the number of days between two dates. (Again, these are just examples, I wouldn’t actually do it this way.)

For both examples, we use an independent window, so, we have two windows. Both windows have an “OK” button. When you click the “OK” button, the calculation is made and displayed. The second button says “Cancel.” When you press the “Cancel” button, (and here is the issue that I am asking about) the window simply goes away, reasonably enough.

Keep in mind that here we have only two windows, but we could have had twenty windows. Should I be creating a separate “close the window routine,” one for for each window, or should one common “close the window routine” be used by all twenty windows? I can see advantages and disadvantages to both (passing information, etc). However, because I am new to AppleScriptObjective-C, I am looking for the “best approach.”

Any thoughts are greatly appreciated.

Hi,

you are talking about the major benefit of object oriented programming.
Actually you need only a custom class either subclassing NSWindowController, a subclass of NSWindow or even a custom NSObject class which creates the window programmatically.

This class can include custom methods (handlers) and multiple instance variables (parameters) for example
the size of the window, the title of the OK/Cancel button, the math mode, the hidden/enable state of specific UI elements an so on.
Once you need a window you create an instance of the class with alloc/init, set the appropriate variables and show the window (showWindow could be a custom method of the class). Assigning the instance reference to a variable you have access to all instance variables and you can call the custom methods