1/55
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Method:
A program module that contains a series of statements that carry out a task.
Method header:
also called the declaration or definition
Method body:
Contains the implementation (Statements that carry out the tasks).
Method return statement:
Returns control to the calling method.
Method must include
Method header, Method body, and Method return statement.
Local Variables and constants:
declared in a method
Global Variables and constants:
known to all program modules
When methods must share data:
Pass the data into and return the data out of methods.
When you call a method from a program, you must know four things:
What the method does. Name of the called method. Type of information to send to the method, if any. Type of return data to expect from the method, if any.
Argument to the method:
Pass a data item into a method from a calling program.
Parameter to the method:
Method receives the data item.
When a method receives a parameter, you must provide a parameter list that includes:
The type of the parameter. The local name for the parameter.
Signature:
Method’s name and parameter list.
Passed by value:
A copy of a value is sent to the method and stored in a new memory location accessible to the method.
Methods can require more than one parameter.
List the arguments within the method call, separated by commas. List a data type and local identifier for each parameter within the method header’s parentheses. Variables that accept the parameters in the method are called formal parameters.
Creating Methods that Require Parameters.
Passed by value. Each time a method executes, parameter variables listed in the method header are redeclared.
A variable declared within a method ceases to exist when the method
Goes out of scope.
To retain a value that exists when a method ends,
return the value from the method back to the calling method
Return type for a method
Indicates the data type of the value that the method will send back. Can be any type. Also called method’s type. Listed in front of the method name when the method is defined.
Overhead refers to
the extra resources and time required by an operation, such as calling a method.
IPO chart:
A tool that identifies and categorizes each item in a method by input, processing, and output. A method that finds the smallest of three numeric values.
Indicate that a method parameter must be an array.
Place square brackets after the data type in the method’s parameter list.
Arrays are passed by reference.
the method receives the actual memory address of the array and has access to the actual values in the array elements.
Method can also return nothing.
Return type void, Void method.
Overloading:
Involves supplying diverse meanings for a single identifier.
Overload a method:
Write multiple methods with a shared name but different parameter lists.
Polymorphism:
Ability of a method to act appropriately according to the context.
Ambiguous methods:
Situations in which the compiler cannot determine which method to use.
Every time you call a method:
Compiler decides whether a suitable method exists. If so, the method executes. If not, you receive an error message.
Using Predefined Methods:
Modern programming languages contain many methods that have already been written.
Implementation hiding:
Encapsulation of method details. When a program makes a request to a method, it does not know the details of how the method is executed.
Interface to the method
The only part of a method with which the method’s client interacts.
Substitute a new method implementation
As long as the interface does not change, you do not need to make changes in any methods that call the altered method
a black box is
A hidden implementation. You can examine what goes in and out but not how it works.
Cohesion:
How the internal statements of a method serve to accomplish the method’s purpose.
Coupling:
A measure of the strength of the connection between two program methods.
Tight coupling:
Occurs when methods excessively depend on each other. Makes programs more prone to errors. Methods have access to the same globally defined variables.
Loose coupling:
Occurs when methods do not depend on others. Data is passed from one method to another.
Recursion:
Occurs when a method is defined in terms of itself. Calls itself.
Every time you call a method The address to which the program should return is stored in a memory location called
the stack.
Recursive cases:
input values that cause a method to recur.
Base case or terminating case:
input values that makes the recursion stop.
Procedure(s)
A ________ is a block of Visual Basic code that performs a task. Code that is repeated more than once in a program could be put into a ________. Using ________ makes it easier for you and for other programmers to read and maintain your code.
a method is called a ________ in visual basic.
procedure
Sub Procedures
do not return a value back to their calling procedure.
Function Procedures
do return a value back to their calling procedure. you have to indicate the type of data it will return.
the function called Format()
allows you to control the format of numeric output. For example, it can be used to display a number as currency (money).
You can also pass a _________ element to a Sub procedure or Function, just as you pass a variable or constant.
single array
A program can contain a method that
calls another method.
Programmers should strive to _____.
increase cohesion
A method’s interface is its _____.
parameter list, return type, and identifier.
When you use a variable name in a method call, it _____ as the variable in the method header.
can have the same name
When an array is passed to a method, it is _____.
passed by reference
When a method receives a copy of the value stored in an argument used in the method call, it means the variable was _____.
passed by value
Although the terms parameter and argument are closely related, the difference is that argument refers to _____.
a value in a method call
When you write the declaration for a method that can receive a parameter, which of the following must be included in the method declaration?
A local name for the parameter, and the data type of the parameter.