15.04.2018 Views

programming-for-dummies

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

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

Organizing a Program with Object-Oriented Programming 43<br />

The user can do dozens of different possible events, but the most common<br />

events are clicking the mouse or moving the mouse pointer over an item.<br />

Event handlers typically do one of three things:<br />

Book I<br />

Chapter 2<br />

✦ Identify what the user did, such as click a button<br />

✦ Retrieve in<strong>for</strong>mation from the user interface, such as when the user<br />

types something in a text box<br />

✦ Display in<strong>for</strong>mation to the user, such as displaying an error message<br />

After you’ve written one or more event handlers <strong>for</strong> your user interface, you<br />

have a complete working user interface. Now you just have to attach this<br />

user interface to a working program.<br />

Different Methods<br />

<strong>for</strong> Writing<br />

Programs<br />

Writing your program<br />

Some people write their program first and then design a user interface<br />

around it. Other people design their user interface first and then write their<br />

program to work with it. The whole point of event-driven <strong>programming</strong> is to<br />

separate your program from your user interface so you can focus on making<br />

each part work individually.<br />

Event-driven <strong>programming</strong> focuses mostly on designing a user interface and<br />

making it work, but does little to help you write your actual program. To<br />

write your program, you can use structured <strong>programming</strong> or object-oriented<br />

<strong>programming</strong> (or both, or neither).<br />

After you’ve written your program, you “attach” the program to your user<br />

interface by writing event handlers. Event handlers “glue” your user interface<br />

to your actual program. With event-driven <strong>programming</strong>, you can be<br />

pretty sure that your user interface will always work perfectly. You just have<br />

to worry about errors in your main program.<br />

Organizing a Program with Object-Oriented<br />

Programming<br />

Structured <strong>programming</strong> helps you organize and divide your program into<br />

smaller, more manageable pieces. For small- to medium-sized programs,<br />

dividing a program into smaller programs is fine, but the larger your program<br />

gets, the more smaller programs you’ll have to worry about. Eventually, computer<br />

scientists discovered that they needed another technique <strong>for</strong> dividing<br />

large programs into parts, so they called this new technique object-oriented<br />

<strong>programming</strong> (often abbreviated as OOP).

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

Saved successfully!

Ooh no, something went wrong!