Creating Classes for Reuse

We frequently will create a class for something that we will use many times. For example, we could create a generic "OK" button that simply closes a form. If we create a class once, we can reuse that button as many times as we want without having to write a single line of code.

Classes can be more complex than a simple OK button. For example, we can create a drop down list object (comparable to the popup list in Microsoft® FoxPro® 2.6) that would get a list of all drives on the system and allow the user to select one. This type of object (we'll see an example of one later on), is more complex than a simple OK button and benefits more from the object oriented approach.

Coding classes for reuse is one of the primary reasons we create classes. In fact, the majority of the classes we create in our applications will probably fall into this category. In addition to creating Visual Classes (classes that we use for our application's graphical user interface (GUI), we can also create classes that model the business entities in our applications such as customers, invoices, and so on. Again, the idea is that we would model the behaviors of these objects only once and then could reuse them, either by instantiating objects directly from the classes or using the classes as bases for other subclasses.