Designing Methods
- One of the first things to decide is which class a method should go in. We'll talk more about this when we talk about class design. For now, I'll just tell you and it will either go into a helper class, or an Applet, or into the class that has your main().
- A method in your application (with main()) should be static. No other methods should be static unless I tell you to make it static.
- When do you decide that you need a method?
- if you have a lot of details
-
if the idea of the function seems re-usable.
-
Once you have decided to create a method, and have a good idea what the method will do, you should:
-
Pick a name that captures what the function does.
-
Decide on the parameters and the datatype for each.
-
Pick a name for each parameter that captures what the argument stands for.
-
Decide on a return value, if necessary, and determine the return type of the function.
- After you have determined the signature of your method, next you
determine the algorithm and write the code for the method. Then you test
it.