< Previous | Contents | Next >

Understanding Software Reuse

You can reuse functions in other programs. For example, since asking the user a yes or no question is such a common thing to do in a game, you could create an askYesNo() function and use it in all of your future game programs. So writing good functions not only saves you time and energy in your current game project, but it can save you effort in future ones, too.

Rea l Worl d

image

It’s always a waste of time to reinvent the wheel, so software reuse—employing existing software and other elements in new projects—is a technique that game companies take to heart. The benefits of software reuse include:


n Increased company productivity. By reusing code and other elements that already exist, such as a graphics engine, game companies can get their projects done with less effort.

n Improved software quality. If a game company already has a tested piece of code, such as a networking module, then the company can reuse the code with the knowledge that it’s bug-free.

n Improved software performance. Once a game company has a high-performance piece of code, using it again not only saves the company the trouble of reinventing the wheel, it saves them from reinventing a less efficient one.


image


You can reuse code youve written by copying from one program and pasting it into another, but there is a better way. You can divide up a big game project into multiple files. Youll learn about this technique in Chapter 10, Inheritance and Polymorphism: Blackjack.