6 20 2 What Is Using a Reusable Part Like

Visual LANSA

6.20.2 What Is Using a Reusable Part Like?

It's like using any other component such as a push button. A reusable part presents to the outside world:

  • A set of properties – which you can set and get just like the properties associated with a push button.
  • A set of methods – which you can invoke to request that the part performs some activity.
  • A set of events – which you can monitor for so that you are notified when something significant happens within the reusable part.

You are probably comfortable now with these concepts in the context of a simple component such as a push button or, for example, a list view.

When you create a list view, you must add the columns to it, load the details from a table, and then monitor for events indicating items in the list have been selected or deselected.

This is not really a complex task but there are two situations where you should create the list as a reusable part:

  • If this department list is used on more than one form, you have to repeat the definition, loading and handling logic in all the different programs.
  • If you want to change or enhance the list logic (or your logic has a defect in it) you have to change it in all the different programs. 

Imagine you had a department list view defined in the repository as a reusable part:

Imagine that it publishes a property named uCurrentDept (which tells you the department code currently selected) and it signals an event named uDeptChanged (which tells you that a department selection has been made).

Imagine that in all other respects it looks after itself. It loads the list, handles the selection and deselection logic etc.

To you, a user of this reusable part, it is simply a black box (in other words an encapsulation) that creates a list of departments on your form, tells you when a department is selected (via the uDeptChanged event) and lets you query what the department code of the currently selected department is (via the uCurrentDep property).  

Wouldn't this making designing and coding any application that needed to present a list of departments to the user much quicker, easier, more consistent and easier to maintain?

Finally imagine you have a large library of reusable parts and can assemble many of the things on your forms simply by drawing together pre-assembled and pre-tested components (reusable parts). The only code you need to write is to "glue" the reusable parts together in a logical manner.

Ý 6.20 Reusable Parts