CS 1130: Transition to OO Programming
Module 2, Part 1
More on Methods
You have seen functions or procedures in other languages, so we do not go into an elaborate discussion here. For concepts and ideas that are similar to those in many other languages, we provide brief summaries on html pages and point you to further readings in the course text. For new material, we provide more complete explanations in web lectures.
1. The Importance of Method SpecificationsWeb Lecture
Comments: We discuss method specifications and the standards and conventions we use in this course.
2. Method Headers
Comments: We summarize method headers and show the difference in a header for a function, a procedure, and a constructor.
2. Function and Procedure Calls
Comments: We show what calls look like.
4. Local VariablesWeb Lecture
Comments: A local variable is a variable that is declared in the body of a method. We discuss its use and its scope.
5. Placing Local VariablesWeb Lecture
Comments: The tendency is to put local variable declarations at the beginning of the method body. Don't do it. Instead, put the declarations where they belong, logically speaking, which is generally close to their first use.
6. The Block, Conditional, and Loop Statement
Comments: Conditional statements are essentially the same in all languages. Here, we briefly summarize their syntax and execution.
Gries/Gries Chap. 7 contains a thorough study of while loops and for loops. You will not be tested on this material, but you may have to use loops in the asssignments. Use this chapter as a reference.
Comments: We briefly summarize one-dimensional arrays. This is for your convenience only; you do not have to read this page. Arrays may be used as a matter of course in an assignment, but you do not have to know about them for a test.
Gries/Gries Chaps. 8 and 9 contains a thorough study of one-dimensional and multi-dimensional arrays. You will not be tested on this material, but you may have to use arrays in the asssignments. Use these chapters as a reference.
Comments: Execution of a method can be terminated using a return statement. The return-statement for a function includes an expression, whose value is returned; the return-statement in a procedure or constructor does not.
9. Executing Method CallsWeb Lecture
Comments: We show in detail how a method call is executed, including drawing a frame for the call and erasing it when the call is finished. This material is important because it allows you to answer various questions about methods, such as how long a local variable "lives" and when it is created as well as how the parameter-argument correspondence is managed.
Sec 2.7 of Gries/Gries talks about a "call stack", which contains all the frames for calls still being executed. In this blecture, we abstract away and don't mention the call stack; we just draw the frame for a call anywhere we want.