![]() |
Method Design Patterns |
III. Method Design Patterns There are three steps to successfully designing a method:
The overall program design determines the purpose of each individual
method. In this section we consider
patterns for determining the receives and returns of methods. In some cases
simple algorithms are also included. It turns out that, in most cases, the
purpose of a method determines the rest. In other words, by matching the
patterns below with the purpose of a method you are designing, you can save
yourself a lot of work in designing your mehtods. And, you can feel more
secure that your design is correct. Note that the purpose statements below are very general. When designing a
method, your purpose statements should be more specific, for example:
However, when you go to match the purpose statement of your method with the
purpose's listed here, ignore the extra details you have provided. In other
words, if your purpose statement includes the word 'input' or 'get', you
probably should work with pattern A below. Likewise, if your purpose statement
includes the word 'calculation' it should consider pattern C. Once you have finished designing your methods, you may want to use the algorithmic
patterns to help develop an algorithm or write the code. This is especially
true if the method is at all complex. Simply try to match the purpose of the
method with the purpose statements provided with each algorithmic pattern.
Goal: The appropriate variable(s) contain the value(s) Receives: Nothing Returns the variable Algorithm: Get the value(s) for the variable(s) from the
user
Goal: The screen displays the value(s) Receives: the value(s) Returns NONE Algorithm: Output the value(s)
Goal: Some variable holds the result of the calculation Receives: the value(s) needed for the calculation Returns: the value calculated Pattern D: Message Display
Goal: The message is displayed Receives: None Returns: None Algorithm: Display the message.
|