Our objective in this example is to ensure that the database is hidden from the developer and the user. We’ll achieve this by encapsulating the physical database data content and structure within a business object with methods and properties. To do this, we need to create an ActiveX EXE, which fronts the Company Stock.mdb sample database. We’ll use the resulting ActiveX EXE throughout all the examples in this chapter, demonstrating the reuse of common components and the ease with which a developer or user can learn to utilize a number of methods and properties rather than the underlying data structure and SQL to retrieve the data.
Folder: | CHAP03\Business Object |
Dependencies: | Microsoft DAO 3.5 Object Library |
Project Name: | CompanyStock.vbp |
Instructions: | Load Visual Basic 5, and open the CompanyStock.vbp file. Select Make CompanyStock.exe from the File menu to register the component. |
Our first step is to make sure we have the right methods and properties exposed for the developer to use. To do this, we analyze the table relationship diagram in Figure 3-6 and identify the user requests (which are assumed here). I’ve come up with the following set of public objects for the ActiveX component:
Classes | Public Methods |
CompanyDetails (object) | BuildCompanyCriteria |
Companies (collection) | BuildCompanyList |
Company (data item) | GetCompanyList |
Stocks (collection) | RemoveCompanyList |
Stock (data item) | GetStockList |
CFields (collection) | Item (companies and stocks) |
CField (data item) |
Public Properties | Public Constants |
DataPassFormat | csPassByProperties |
Count (companies and stocks) | csPassByVariant |
csPassByFile |
Figure 3-6 Table relationship diagram for Company Stock.mdb