ATL Development   «Prev  Next»
Lesson 8 Designing application data structures and properties
Objective Design application-specific data structures and properties for PhBook.

Designing Application Data Structures and Properties

Before we start coding, we need to design application-specific data structures, properties, and methods.

Data structures


The first structure we need is a phone record--called PhRec:
#define NAME_SIZ 80
typedef struct {
TCHAR firstName[NAME_SIZ];
TCHAR lastName[NAME_SIZ];
TCHAR phNumber[NAME_SIZ];
} PhRec;

To keep things simple:
  1. PhRec keeps first name, last name, and the phone number--all in buffers of size NAME_SIZ.
  2. Phone records will be stored in a fixed-size array called m_PhRecs in CPhBookObj.
  3. Phone records will not be sorted and duplicates will be allowed.
  4. Phone records will not be saved after the server exits.

PhRec uses "generic" character type TCHAR. TCHAR works with Visual C++'s generic text mapping library functions and macros to support multiple character sets i.e. single-byte (SBCS), multi-characters (MBCS), and Unicode. See the Visual C++ documentation for more details.

Properties

: LONG CurRec
A read-write property that is used to position an index to the active or "current" record. To get a phone record, set CurRec set to the zero-based index of a record and call IReadPhBook::GetPhoneRec (see below).

LONG NumRecs A read-only property that holds the number of stored records.
LONG MaxRecs A read-only property that holds the maximum number of records that can be stored.

IReadPhBook will have only one method:
HRESULT GetPhoneRec([in] PhRec *pPhRec, [out] BOOL *pOK) Get the phone record indexed by property CurRec. If the call is successful, pPhRec contains the information in the phone record indexed by CurRec, and pOk is TRUE.
If an error occurs, i.e., there are no records in the phone book==pOK is set to FALSE.

IManagePhBook will have two methods:
HRESULT AddPhoneRec([in] PhRec *pPhRec, [out] BOOL *pOK) Adds a phone record to the end of PhBookObj's array of phone records. If the record is successfully added, pOK is TRUE. If an error occurs (i.e., there is no more room), pOK is FALSE.
HRESULT DeletePhoneRec([out] BOOL *pOK) Deletes the current record indexed by CurRec. If the call is successful, pOK is TRUE; otherwise, it is set to FALSE.

IManagePhBook does not have CurRec, NumRecs, and MaxRecs properties.
We will have to access these through IReadPhBook. This is OK for now because our goal is to study COM==we are not developing an optimal production phone book application. Having defined our data structures, properties, and methods, we are ready to start coding. The next lesson will get us started.