7.1. IntroductionExperience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces. This technique is called divide and conquer. We introduced methods in Chapter 3. In this chapter, we study methods in greater depth. We emphasize how to declare and use methods to facilitate the design, implementation, operation and maintenance of large programs. You'll see that it is possible for certain methods, called Shared methods, to be called without the need for an object of the class to exist. You'll declare a method with more than one parameter. You'll see how Visual Basic keeps track of which method is currently executing, how local variables of methods are maintained in memory and how a method knows where to return after it finishes executing. We will take a brief diversion into simulation techniques with random-number generation and develop a version of the casino dice game called craps that will use most of the programming techniques you have learned to this point in the book. In addition, we will introduce two techniques for declaring constants in your programs. You'll see that applications can have more than one method of the same name. This technique, called overloading, is used for convenience and clarity when implementing methods that perform similar tasks using different types or numbers of arguments. In certain situations, you can replace a series of overloaded method declarations with a single "generic" methodwe study this powerful code reuse capability in Chapter 25, Generics. |