Part 2. Organizing your programs

 

Sharing code is common among programmers; many problems have been solved by others already, and your solutions could prove useful in your own future projects, to your team, or to the wider developer community. When code modules are shared, it’s important to make clear how others should use them by defining a clear interface, or set of properties and functions you expect users to utilize. The internals of a module—how you make it do its job—should be protected. Part 2 looks at ways of using local rather than global variables to hide a module’s implementation from other code.

As your programs grow, the need for organization increases, and you’ll start to notice patterns and procedures you use again and again. Part 2 also looks at ways of using modules in your code to improve flexibility, reuse, and maintainability. Your code’s flexibility may be improved by executing parts of it only if certain conditions are met, and you’ll see how to specify those conditions with if statements.

The modules you create will usually perform specific, well-defined tasks within a project. Three common types of module are models, for representing and working with data, views for presenting the data in models, and controllers for updating models and views in response to user or system actions.

By the end of part 2, you’ll have broken The Crypt into modules and updated the game to include challenges: puzzles for players to overcome.

sitemap