Subclassing

Instead of defining the same five attributes every time you need a button to close a frame, you can create a button that has all the attributes that you need already defined. You do this by creating a subclass.
A subclass is derived from another class, called a parent class. The subclass inherits all the attributes and methods of that parent. This means that if you change the value of an attribute or the way a method works on the parent, the same change is propagated to the subclass.
You can also define on the subclass new values for attributes that the subclass inherits. These new values override the values that were inherited from the parent class. For example, if the parent class has a width attribute that is set to 50, you can change that value to 100 on the subclass.
This appendix guides you through the process of creating a subclass of the Push Button class. The new subclass overrides the values for the following attributes:
  • commandOnClick
  • height
  • label
  • name
  • width
After making the Close Window Button subclass, you can drag and drop it onto a frame and the button will function without any further configuration. Besides eliminating repetitive work, subclassing helps to ensure conformity: you won't be able to make the mistake of labeling one button “Close Window” and another “Exit”.