Super

Hi,

I’m trying to advance my knowledge of OOP, as it relates to SC.

I wrote a comment for myself, and for any other developers in my office who may work with this code.

I was hoping you could check it over, and make any corrections to my understanding of what’s going on in the code.

Specifically:

  1. Is a widget I create called a “subclass” or an “instance” (or both)?

  2. Does the location of Super matter (before or after custom code)?

  3. Am I leaving out any important parameters to Super()?

  4. Is this the correct way to implement what I’m trying to do in this specific case? Is there a better way?

Thanks,
Mike

isc.Window.create({
  ID: "submittedInvoiceWindow",
  title: "Submitted Invoices",
  autoDraw:false,
  items: [submittedInvoiceLayout],
  show: function() {
		
    // When we create this isc.Window called "submittedInvoiceWindow"
    // we are actually creating a subclass of the class isc.Window
    // (...Or is it called an "instance" ? )
		
    // Normally, when we call the "show" method
    // it executes the code stored in the parent, or "super" class
    // which is usually sufficient and we don't need to mess with it at all
		
    // However, in some cases, the usual course of action is not enough
    // and we need to "override" the default behavior
		
    // For instance, in this case, it's not enough to simply
    // "show" this Window because the data in its listGrid may have
    // become stale since the last time the user viewed and closed
    // the window
		
    // (The "submittedInvoiceWindow" instance remains in memory
    // even when closed).  We can destroy it when closed, but that's
    // another topic for later...
		
    // So, we want to add our own code to the "show" method
    // to tell the listGrid to refresh its data each time
		
    // However, we don't want to *replace* the default isc code
    // We want to run our code *in addition to* the default code
		
    // So we make a call to Super()
    // This will run the default isc code

    // If we don't include this command
    // Our custom code would run, but the original isc code would not!
		
    // The first parameter for super is the original method to call
    this.Super('show');
		
    // Now we can include our code below
		
    // We need to refresh the data whenever this window is shown
    postedInvoiceList.data.invalidateCache();
		
    // Does it matter if Super() is called first or last?
				
  }
});

Mike,

  1. The widget would be called an “instance” of the Window class. You can also define new classes (subclass) based on a parent class and then create instances of the subclass. (see isc.defineClass())
  2. The location can matter a lot. If you need the parent class to have completed its normal show setup, you need to call Super first. There are times you may want to alter the behavior of the parent class method and call Super after your code. Or of course a mixture is possible. In your specific case it shouldn’t matter and I tend to call Super first unless altering its behavior.
  3. In this case you may be fine but I always use the form this.Super(“method”, arguments) which passes any arguments that were received in the local instance to the super class method. Note that “arguments” is the literal term and will always be “arguments”.
  4. I think your fine with your implementation at a glance. I’m assuming this window will be shown/hidden multiple times and each time you show it you want the data to be discarded and fetched again.

Note that some event handler methods that you can implement are not actually implemented by the parent class and a call to Super does not make sense.

I hope this helps.
dave

Hi Dave,

Thanks for your feedback. That helps a lot.

Mike