30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

10.2.11 OutputContext<br />

10.2 Das DDD 279<br />

Abhängig davon, ob es sich nun um e<strong>in</strong>en Text-, Graphik- oder anderen<br />

Kontext handelt, stehen verschiedene Methoden <strong>in</strong> diesem Kontext zur<br />

Verfügung. Diese können nicht wirklich <strong>in</strong> e<strong>in</strong>er Basisklasse deklariert werden,<br />

denn sie s<strong>in</strong>d e<strong>in</strong>fach zu unterschiedlich und nicht vorhersehbar. Aus<br />

diesem Grund ist die abstrakte Basisklasse OutputContext auch dementsprechend<br />

primitiv gestaltet:<br />

1<br />

2 #ifndef s i m p l e o u t p u t c o n t e x t h<br />

3 #def<strong>in</strong>e s i m p l e o u t p u t c o n t e x t h<br />

4<br />

5 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

6 /∗ The base c l a s s f o r a l l d i f f e r e n t output contexts . I t i s<br />

7 ∗ used <strong>in</strong> context with the Displayable i n t e r f a c e .<br />

8 ∗/<br />

9<br />

10 class OutputContext<br />

11 {<br />

12 public :<br />

13<br />

14 /∗ Destructor<br />

15 ∗ Just to make sure that a v i r t u a l d e s t r u c t o r e x i s t s<br />

16 ∗/<br />

17 virtual ˜ OutputContext ( ) { }<br />

18<br />

19 /∗ Returns a clone of the output context . Has to be overridden<br />

20 ∗ by a l l derived c l a s s e s to d e l i v e r a clone o f the c o r r e c t<br />

21 ∗ type . This clone has to be dynamically a l l o c a t e d via new<br />

22 ∗ and the c a l l e r i s r e s p o n s i b l e to d e l e t e i t i f no longer<br />

23 ∗ needed .<br />

24 ∗ @return A po<strong>in</strong>ter to the dynamically generated clone o f t h i s<br />

25 ∗ OutputContext . This clone has to have exactly the<br />

26 ∗ type of the derived c l a s s .<br />

27 ∗/<br />

28 virtual OutputContext ∗ getClone ( ) = 0 ;<br />

29 } ;<br />

30<br />

31<br />

32 #endif // s i m p l e o u t p u t c o n t e x t h<br />

10.2.12 TextOutputContext<br />

Die Ausprägung des Output Contexts, die im Spiel Verwendung f<strong>in</strong>det, ist e<strong>in</strong><br />

ganz primitiver TextOutputContext, der gerade eben e<strong>in</strong>mal e<strong>in</strong> paar Methoden<br />

besitzt, über die man Daten ausgeben kann. Diese werden e<strong>in</strong>fach auf<br />

cout geschrieben. Mit dem Wissen um Streams, die noch <strong>in</strong> Abschnitt 16.6<br />

kurz umrissen werden, könnte man diesen Kontext natürlich sauberer gestalten.<br />

1 // s i m p l e t e x t o u t p u t c o n t e x t . h − a simple text output context<br />

2<br />

3 #ifndef s i m p l e t e x t o u t p u t c o n t e x t h<br />

4 #def<strong>in</strong>e s i m p l e t e x t o u t p u t c o n t e x t h

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!