This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Lesson 4 (Classes Part 2)
Sally Steuterman edited this page Jul 28, 2020
·
1 revision
- How to customize fields with the keywords
readonly
andstatic
. - How to add methods to a class and call those methods.
- The difference between instance methods and static methods.
- How to override the default
ToString
andEquals
methods for a class. - How to auto-generate an
Equals
method in Visual Studio.
- The class 5 prep work should be active by the end of class.
- Graded Assignment 2 is open, and it is due soon. Keep working on your project! After today, you will have enough skill to make significant progress.
- Q&A for the prep work exercises.
- The words
readonly
andstatic
can be confusing if the students take the latter term to mean "unchanging". Be sure to review what each keyword means and the results of applying each one to a field. - Pay particular attention to why we want to use the
Equals
method rather than the==
operator to compare objects.- Review the difference between comparing identity vs. equality.
- Note the default behavior of the
Equals
method. - Touch upon the
GetHashCode
method and its relationship toEquals
- Review why students will usually want to code their own
ToString
andEquals
methods. - Review how to call methods using
ClassName.MethodName
vs.objectName.MethodName
.- When and why does it matter which syntax to use?
- Review the objectives for today's studio task. Alternatively, if the TAs raise concerns about how the students are progressing on Assignment 2, replace the studio intro with a review of the Assignment 2 objectives.
- This studio extends the restaurant menu that the students started in class 3. Today, they will create methods to add and remove menu items, as well as to print the menu.
- Pace the studio carefully. Just like last class, the students will begin planning their class methods using pen and paper, then pair up to share their ideas.
- Provide ample time for this sharing. However, the students will need more time to get their methods coded compared to the last studio, so plan accordingly.
- As the students get further into their coding, rotate through your group and have them demonstrate their program. Verify that they can add or remove new menu items and that they can print a menu to the screen.
- Just like the last studio, it is important to make sure the students' code works and matches their design.
- Encourage students to think about the principles of OOP and to consider how to best encapsulate their code.
- If a student's code differs significantly from their design, ask them (carefully) about why they decided to adapt their plan.