12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

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.

134 Day 5<br />

That looks just a little <strong>in</strong>timidat<strong>in</strong>g, doesn’t it? The fact is, I even had to get some help from<br />

my friends on the BCPPLIB forum of CompuServe (thanks, Paul!). Now look at the<br />

equivalent us<strong>in</strong>g <strong>Borland</strong>’s Object W<strong>in</strong>dows Library, shown <strong>in</strong> List<strong>in</strong>g 5.2.<br />

List<strong>in</strong>g 5.2. OWL code to load and display a bitmap.<br />

1: TDib dib(“test.bmp”);<br />

2: TPalette pal(dib);<br />

3: TBitmap bitmap(dib, &pal);<br />

4: TClientDC dc(*this);<br />

5: dc.SelectObject(pal);<br />

6: dc.RealizePalette();<br />

7: TMemoryDC memdc(dc);<br />

8: memdc.SelectObject(bitmap);<br />

9: dc.BitBlt(0, 0, bitmap.Width(), bitmap.Height(), memdc, 0, 0);<br />

So which would you rather use? You don’t even have to know what these code snippets do<br />

to make that decision. It’s easy to see that the OWL version is shorter and more readable.<br />

(VCL makes the task even easier by provid<strong>in</strong>g a bitmap component that you drop on a form.<br />

I don’t want to get ahead of myself, though, so I’ll save that discussion for a little later.)<br />

These examples sum up what frameworks are all about. Frameworks hide details from you<br />

that you don’t need to know about. Everyth<strong>in</strong>g that is conta<strong>in</strong>ed <strong>in</strong> List<strong>in</strong>g 5.1 is performed<br />

beh<strong>in</strong>d the scenes <strong>in</strong> the OWL code <strong>in</strong> List<strong>in</strong>g 5.2. You don’t need to know every detail about<br />

what goes on beh<strong>in</strong>d the scenes when OWL does its th<strong>in</strong>g, and you probably don’t want to<br />

know. All you want to do is take the objects that make up a framework and put them to use<br />

<strong>in</strong> your programs.<br />

A good framework takes full advantage of OOP. Some do that better than others. <strong>Borland</strong>’s<br />

Object W<strong>in</strong>dows Library and Visual Component Model are tremendous examples of objectoriented<br />

programm<strong>in</strong>g. They provide the proper abstraction needed for you to rise above the<br />

clutter and get down to the serious bus<strong>in</strong>ess of programm<strong>in</strong>g.<br />

So What’s the Catch?<br />

A little skeptical, are you? Good. You’re bright enough to figure out that if you have all of<br />

that ease of use, you must be giv<strong>in</strong>g someth<strong>in</strong>g up. Truth is, you are right. You might th<strong>in</strong>k<br />

that a program written with a framework will be larger and slower than its counterpart written<br />

<strong>in</strong> C. That’s partially correct. Applications written with frameworks don’t necessarily have<br />

to be slower than programs written <strong>in</strong> C, though. There is some additional overhead <strong>in</strong>herent<br />

<strong>in</strong> the <strong>C++</strong> language, certa<strong>in</strong>ly, but for the most part it is not noticeable <strong>in</strong> a typical W<strong>in</strong>dows<br />

program.

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

Saved successfully!

Ooh no, something went wrong!