15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

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

138<br />

Creating a User Interface<br />

Sounds like a lot of work just to make a simple change? It is, and that’s why<br />

loose coupling between subprograms is so important. Because programmers<br />

can’t always be trusted to make sure their subprograms are loosely coupling,<br />

OOP <strong>for</strong>ces them to do it whether they like it or not.<br />

Creating a User Interface<br />

The three actions of most programs are<br />

✦ Get data.<br />

✦ Manipulate that data.<br />

✦ Create a result.<br />

A football-picking program takes in data about both teams, uses a <strong>for</strong>mula to<br />

predict a winner, and prints or displays its answer on-screen. A hotel reservation<br />

program gets a request <strong>for</strong> a room from the user (hotel clerk), scans<br />

its list of rooms <strong>for</strong> one that’s available and that matches the user’s criteria<br />

(no smoking, two beds, and so on), and displays that result on-screen.<br />

Basically, every program takes in data, calculates a result, and displays that<br />

result. To accept data from the user and display a result back to the user<br />

again, every program needs a user interface, as shown in Figure 1-9.<br />

Figure 1-9:<br />

The user<br />

interface<br />

accepts<br />

data and<br />

displays the<br />

results of its<br />

calculations<br />

back to<br />

the user.<br />

User<br />

Give data<br />

Display new data<br />

User<br />

Interface<br />

Give data<br />

Return new data<br />

Main<br />

Program

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

Saved successfully!

Ooh no, something went wrong!