From f3446a91767eeeb483dac09507033a354d5cd700 Mon Sep 17 00:00:00 2001 From: Charisee Chiw Date: Tue, 24 Jan 2023 10:46:13 -0800 Subject: [PATCH] Speaker notes for methods.md (#202) * Update methods.md * Update methods.md * Update methods.md * Reword explanation of methods Co-authored-by: Andrew Walbran --- src/methods.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/methods.md b/src/methods.md index ae599dd6..35ac5f58 100644 --- a/src/methods.md +++ b/src/methods.md @@ -25,3 +25,17 @@ fn main() { } ``` +
+ +Key Points: +* It can be helpful to introduce methods by comparing them to functions. + * Methods are called on an instance of a type (such as a struct or enum), the first parameter represents the instance as `self`. + * Developers may choose to use methods to take advantage of method receiver syntax and to help keep them more organized. By using methods we can keep all the implementation code in one predictable place. +* Point out the use of the keyword `self`, a method receiver. + * Show that it is an abbreviated term for `self:&Self` and perhaps show how the struct name could also be used. + * Explain that Self is a type alias for the type the `impl` block is in and can be used elsewhere in the block. + * Note how self is used like other structs and dot notation can be used to refer to individual fields. + * This might be a good time to demonstrate how the `&self` differs from `self` by modifying the code and trying to run say_hello twice. +* We describe the distinction between method receivers next. + +