2.15.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:

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:

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.