M/F 2:30-3:20   
in Philips 101

CS 1130: Transition to OO Programming

Spring 2015

Part 2. More on 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.


Contents

1. The Importance of Method Specifications

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec.13.3.1, pp. 376–378.

Comments: We discuss method specifications and the standards and conventions we use in this course.


2. Method Headers

Reading: Lecture Notes
Gries/Gries, Sec. 2.1—2.3.3, pp. 45–62.

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

Reading: Lecture Notes
Gries/Gries, Sec. 2.1—2.3.3, pp. 45–62.

Comments: We show what calls look like.


4. Local Variables

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec. 2.3.7, pp. 76–78; p. 371; p. 383–384.

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 Variables

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec. 2.3.7, pp. 76–78; p. 371; p. 383–384.

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

Reading: Lecture Notes
Gries/Gries Sec. 2.3.3, pp. 68–71; Sec. 2.3.8, p.p 78-81; Chap. 7, pp 233–265.

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.


7. Arrays

Reading: Lecture Notes
Gries/Gries Chaps. 8 and 9.

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.


8. Return-Statements

Reading: Lecture Notes
Gries/Gries Secs. 2.3.5–2.3.6, pp. 7476.

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 Calls

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec. 2.7, pp. 93–97.

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.