Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Symbian OS Explained - Effective C++ Programming For Smartphones (2005) [eng].pdf
Скачиваний:
60
Добавлен:
16.08.2013
Размер:
2.62 Mб
Скачать

COMPATIBILITY AND THE SYMBIAN OS CLASS TYPES

291

IMPORT_C virtual CSiamese(); public:

IMPORT_C virtual void EatL(); // Overrides base class functions

IMPORT_C virtual void SleepL();

// ...

};

//Function definitions not relevant to the discussion have been

//omitted

void CSiamese::EatL()

{// Overrides base class implementation

... // Omitted for clarity

}

void CSiamese::SleepL()

{// Calls base class implementation CCat::SleepL();

}

Provide ”Spare” Member Data and Virtual Functions

As you’ll have gathered from a number of the guidelines above, the use of virtual functions, although powerful in a C++ sense, can be quite limited in terms of extensibility when compatibility must be maintained. If it is possible that your class may need to be extended (and this is often hard to determine, so you may prefer to assume that it will), then you should add at least one reserve exported virtual function. This will give you the means by which to extend the class without disrupting the vtable layout of classes which derive from the class. In effect, this provides a means to get around the limits by which virtual functions may be extended, through the use of explicit interface design. You should, as always, implement any reserved functions, defaulting them to perform no action.

By the same token, you may wish to reserve at least four extra bytes of private member data in classes which may later need to be extended. This reserved data can be used as a pointer to extra data as it is required. Of course, if the class is internal to your component, or is unlikely to require later modification, you should not reserve extra memory in the class object, in order to continue to minimize the use of limited memory resources.

18.7 Compatibility and the Symbian OS Class Types

Chapter 1 describes the main class types, and their characteristics, on Symbian OS. The discussion in this chapter has mainly focused on compatibility issues which apply to C class objects and, to a lesser extent, R classes. T classes, by their very nature, tend to be stack-based and are often simple, taking a similar role to a C struct. T classes frequently

292

COMPATIBILITY

do not have constructors and never have destructors. Once a T class is publicly defined, it is often difficult to make client-compatible changes to it.

18.8Summary

A change is acceptable if every line of code affected by it can be altered, where necessary, and the code rebuilt against the changes. In effect, this often means that a change must be restricted to the internals of a component rather than its public API. For this reason, you should endeavor to keep private definitions and header files (and anything else which is likely to be subject to change) out of the public domain.

A change is also acceptable if it can be verified as compatible, according to the guidelines I’ve discussed here. In general, the key compatibility issue for shared library DLLs is backward binary compatibility, with source compatibility an additional aim.

These guidelines derive from those used within Symbian, in accordance with the C++ standard. I am very grateful to David Batchelor, John Forrest and Andrew Thoelke of Symbian who have previously written guides to compatibility best practice on Symbian OS, which I used as the basis of this chapter.