03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

used in preference to old style C casting, as by doing this you get the benefit of C++ cast<br />

checking. Previous versions of the SDK defined macros that expanded to these keywords,<br />

for compatibility with older versions of GCC that did not support C++ casting. These are now<br />

deprecated – current compilers can use the standard C++ definitions.<br />

3.7 Classes<br />

As you'd expect, classes are used to represent objects, abstractions, and interfaces.<br />

Relationships between classes are used to represent relationships between objects or<br />

abstractions. The most important relationships between classes are the following:<br />

� uses-a: if class A uses-a class B, then A has a member of type B, B&, const B&, B*,<br />

or const B*, or a function that can easily return a B in one of these guises. A can then<br />

use B's member functions and data.<br />

� has-a: has-a is like uses-a, except that A takes responsibility for constructing and<br />

destroying the B as well as using it during its lifetime.<br />

� is-a: if class A is-a class B, then B should be an abstraction of A. is-a relationships are<br />

usually represented in C++ using public derivation.<br />

� implements: if class A implements an interface M, then it implements all M's pure virtual<br />

functions. Interface implementation is the only time multiple inheritance is used in<br />

Symbian OS.<br />

Sometimes, abstract/concrete notions are blurred. CEikDialog is concrete as far as its<br />

implementation of CCoeControl is concerned, but in fact CEikDialog is an essentially<br />

abstract base class for user-specified dialogs or Uikon standard dialogs such as a<br />

CEikInfoDialog. Some classes (such as both CCoeControl and CEikDialog) contain<br />

no pure virtual functions, but are still intended to be derived from. They provide fall-back<br />

functionality for general cases, but it is likely that one or two functions will need to be<br />

overridden to provide a useful class.<br />

3.7.1 Interfaces<br />

Symbian OS makes quite extensive use of interface classes (originally called mixins). An<br />

interface is an abstract base class with no data and only pure virtual functions.<br />

APIs that have both library and framework aspects often define their library aspect by means<br />

of a concrete class and their framework by means of an interface class. To use such an API,<br />

you need to use the concrete class and implement the interface.<br />

The Symbian OS PRINT API provides an example. In addition to library classes to start the<br />

print job, there are framework classes for printing part of a page, and for notifying the<br />

progress of the job to an application. MPrintProcessObserver is the interface for<br />

notifying progress:<br />

class MPrintProcessObserver<br />

{<br />

public:<br />

virtual void NotifyPrintStarted(<br />

TPrintParameters aPrintParams) = 0;<br />

virtual void NotifyBandPrinted(<br />

TInt aPercentageOfPagePrinted,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!