13.07.2015 Views

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Inheritance</strong> <strong>and</strong> <strong>Polymorphism</strong> 1024WindowRepOwnsarray <strong>of</strong> characterswith screen contentDoesput character on screenmove cursorget inputdelaysSingleton class;WindowOwnsposition relative to screenarrays <strong>of</strong> characterswith background <strong>and</strong>current contentdimensions, framing flagDoesput character in current(or background) imageorganize drawing (all orjust content area)clear current imagereturn size details etc.NumberItemEditTextOwnsnumeric value <strong>and</strong> labelDoesset value (<strong>and</strong> change display)return current valueOwnslabel, text buffer,size limitDoesaccept input charactersreturn text bufferset text bufferFigure <strong>29</strong>.2Class WindowRep <strong>and</strong> the Windows class hierarchy."Singleton" patternA class for which there can only be a single instance, an instance that must beaccessible to many other objects, an instance that may have to create auxiliary datastructures or perform some specialized hardware initialization – this is a commonpattern in programs. A special term "singleton class" has been coined to describethis pattern. <strong>The</strong>re are some st<strong>and</strong>ard programming "cliches" used when codingsuch classes, they are followed in this implementation.<strong>The</strong> unique WindowRep object used in a program provides the followingservices:• PutCharacterOutputs a character at a point specified in screen coordinates.• MoveCursorPositions the "cursor" prior to an input operation.• GetCharInputs a character, echoing it at the current cursor position• ClearClears the entire screen.• CloseDownCloses down the windowing system <strong>and</strong> gets rid <strong>of</strong> the program's WindowRepobject

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

Saved successfully!

Ooh no, something went wrong!