Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


992


FIGURE 28.10

The Products_OOP form demonstrates unbound object-oriented techniques.


Retrieving product details
The first enhancement to the Product class is to update the process of retrieving product details,
given a particular ProductID. In the initial example, the user selected a product from a combo
box, and the form used an inline SQL statement to extract the details for the selected product.

The problem with having the form directly manage data is that the form (which is the consumer of
the product data) has to know a great deal about how the product data is stored. The form holds a
hard-coded SQL statement, creates a recordset with product data, and then assigns the recordset’s
data to the product object’s properties. This is far too much to entrust to the user interface.

Consider an application with perhaps hundreds of forms. Using the design described in the previ-
ous paragraph, each form in the application has to manage its own data. Changing anything in the
database means many different changes have to be made to the user interface, greatly complicating
maintenance.

Two of the primary objectives of object-oriented programming are code-reuse and data abstraction.
We all know and understand code reuse: Write the code once, and use it many different places.
Data abstraction is a bit more complex, but it’s based on the notion that each layer of an applica-
tion (data management, business logic, and user interface) should do what it does best, and not
have to worry about other parts of the application. The data layer should concern itself with getting
data into and out of the data source. The business logic should concern itself with the rules that
drive the application, and the user interface presents data from the user and manages the applica-
tion’s interaction with the user.

Bundling all those operations behind or within a form violates the notion of data abstraction. Every
form in a bound application knows everything about the data managed by the form. Although this
works well in small applications where complete control over the data is relatively unimportant,
larger, more ambitious applications generally require significant control over the data.
Free download pdf