Chapter 5 : Method Flashcards
What are method used to?
- Break a complex program into small, manageable pieces
public partial class Form1 : Form
{
private void myButton_Click(object sender, EventArgs e)
{
Method2();
}
private void Method2()
{
Statement
}
What is the approach ( break a complex program into small, manageable pieces ) known as?
- Divide & Conquer
What is the general terms for breaking down a program to smaller units of code known as?
- Modularization
List out 2 parts for method definition
- Header
- body
Where method header appears and indicate what?
- Appears at the beginning of a method
- Indicate access mode, return type, and method name
- private void DisplayMessage() {}
What is the difference between a void method and a normal method?
- void method does not return any value to the statement that called it
What is a void method?
- A method that simply executes the statement it contains and then terminates
What is the method body?
- Is a collection of statements that are performed when the method is executed
List out the 4 parts of a method header
- Access Modifier
- Return Type
- Method Name
- Parameter ( Parentheses )
What is the access modifier? What value is available?
- Keywords that defines the access control
- Value Available
- private
- public
What is the difference between private and public method?
- Access control ( private method can be called only by code inside the same class while public class can be called by code outside the class )
What does return type specifies?
- Specifies whether or not a method returns a value
- void - no return
empty - return
What is a method name?
- The identifier of the method, it must be unique in a given program
- Like variable name
What does a method’s name always followed by?
- A pair of parentheses ()
How to create and display a method?
private void goButton_Click(object sender, EventArgs e)
{
MessageBox.Show(“This is the goButton_Click method.”);
DisplayMessage();
}
private void DisplayMessage()
{
MessageBox.Show(“This is the DisplayMessage method.”);
}
What is return point?
- A memory address that the system saves to which it should return
What will happen when the method ends?
- The system jumps back to the return point and resumes execution
What does the system needs to know when calling a method?
- A system needs to know where the program should return after the method ends
What techniques that the programmer commonly use to modularize a program?
- Top-down design
What does a top-down design does?
- Breaks down an algorithm to methods
List out the process for top-down design ( 3 )
- The overall task that the program is to perform is broken down into a series of subtasks
- Each subtask is examined to determine whether it can be further broken down into more subtasks
- Once all subtasks have been identified, they are written in code
- Step 2 will be repeated until no more subtasks can be identified
What is an argument?
- Any piece of data that is passed into a method when the method is called
- MessageBox.Show(“Show”)
What is a parameter?
- A variable that receives an argument that is passed into a method
- private void DisplayValue (int value) {}
What does string parameter accepts?
- Only string arguments