Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”

Similar presentations


Presentation on theme: "Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”"— Presentation transcript:

1 Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.” ~ Morpheus“There is a difference between knowing the path and walking the path.” ~ Morpheus “There is a difference between defining a method and invoking a method.” ~ 120 Prof.“There is a difference between defining a method and invoking a method.” ~ 120 Prof.

2 Fundamentals of Software Development 1Slide 2 Methods Defining, Invoking, Executing Defining a MethodDefining a Method –Specifying stepwise directions for a method… For example you specify how a robot can pick up a soda can (think of this as “teaching”)you specify how a robot can pick up a soda can (think of this as “teaching”) Invoking a MethodInvoking a Method –Asking to activate a method… For example you ask the robot to pick up a soda canyou ask the robot to pick up a soda can Executing a MethodExecuting a Method –Processing the stepwise instructions specified in the method… For example the robot carries out your command to pick up the soda canthe robot carries out your command to pick up the soda can

3 Fundamentals of Software Development 1Slide 3 Defining a Method Format:Format: methodName (ParameterType ParameterName, …) { methodName (ParameterType ParameterName, …) { // Stepwise instructions } ExampleExample String transform (String inputString) { return “Caps:” + inputString.toUpperCase() } Questions?

4 Fundamentals of Software Development 1Slide 4 Invoking and Executing a Method Format: object.method(arguments)Format: object.method(arguments) Invoke a String method:Invoke a String method: –"Hello".toUpperCase() yields "HELLO" –"Hello".substring(3) yields "lo" –"Hello".substring(1, 3) yields "el" –"Hello".substring(0) yields "Hello“ Stringmethoddotarguments, in parentheses Numbering starts at zero Questions?

5 Fundamentals of Software Development 1Slide 5 Signature Signature of a method specifies its input and output but not its definitionSignature of a method specifies its input and output but not its definition –Methods in the same class may have the same name (overloading) –But each method must have a unique signature

6 Fundamentals of Software Development 1Slide 6 Interfaces –Methods may have the same name (overloading) –But each method must have a unique footprint

7 Fundamentals of Software Development 1Slide 7 Interface (Signatures) An interface contains the signature but not body for each methodAn interface contains the signature but not body for each method –Each method must have a unique footprint. For example: interface Clock { Time getTime(); Time getTime(); void setTime(Time x); void setTime(Time x); void setTime(Time x, Station s); void setTime(Time x, Station s);} Two methods may have the same name as long as their signature is different.


Download ppt "Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”"

Similar presentations


Ads by Google