Download presentation
Presentation is loading. Please wait.
Published byJessica Bates Modified over 5 years ago
1
Functions, Return Values, Parameters Getters and Setters
2
Procedures in Everyday Life
We use procedures all time – fire drill or recipe They are set up in advance with a detailed set of instructions We only refer to them (Call them) when we need them Procedures allow us to repeat the same task over and over again
3
Function Procedures Procedures in programming languages are the same
They are set up in advance with a detailed set of instructions We only refer to them (Call them) when we need them Procedures allow us to repeat the same task over and over again
4
Functions are used to make…
Event handlers Public methods in a class Public properties in a class Constructors None of the above just a function
5
Function Example
6
Return Values Two parts of the function work together…
7
Pick the Return Data Type
8
Calling Functions May use function with the assignment operator…
When a function call is completed the flow of code returns to the line where the call was made from!
9
Ignoring the Return Value
10
Void Functions
11
Parameters This code is not very versatile… Add parameters…
12
Use the Parameters
13
Calling the Function with Parameters
14
Benefits of Functions Give greater functionality Hide complexity
Promote code re-use Simplify maintenance
15
Functions gives Greater Functionality
When we want to use the function we simply call it
16
Hides Complexity Who cares how it works?
17
Simplify Maintenance Create a function
Call it multiple times around our system Need to make a change Modify the one function definition All of the multiple calls benefit from the change
18
Functions Promote Code re-use
A function should perform one task well Accept enough data via parameters for the task Return an appropriate value Organise into class libraries Allow us to recycle code
19
Public v Private Public function in a class file
Becomes a method in an object
20
Functions and Public Properties Getters and Setters
21
Using the Debugger with Functions
Use the sample driving test 2 as an example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.