Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Lesson 4 (Classes Part 2)

Sally Steuterman edited this page Jul 28, 2020 · 1 revision

Lesson 4: Classes, Part 2

In the prep work this week, the students learned

  1. How to customize fields with the keywords readonly and static.
  2. How to add methods to a class and call those methods.
  3. The difference between instance methods and static methods.
  4. How to override the default ToString and Equals methods for a class.
  5. How to auto-generate an Equals method in Visual Studio.

Announcements

  1. The class 5 prep work should be active by the end of class.
  2. 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.

Large Group Time (Instructor)

Lesson 4 Topics That Require Careful Attention

  1. Q&A for the prep work exercises.
  2. The words readonly and static 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.
  3. Pay particular attention to why we want to use the Equals method rather than the == operator to compare objects.
    1. Review the difference between comparing identity vs. equality.
    2. Note the default behavior of the Equals method.
    3. Touch upon the GetHashCode method and its relationship to Equals
  4. Review why students will usually want to code their own ToString and Equals methods.
  5. Review how to call methods using ClassName.MethodName vs. objectName.MethodName.
    1. When and why does it matter which syntax to use?
  6. 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.

Small Group Time: Lesson 4 Studio (TA Notes)

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Just like the last studio, it is important to make sure the students' code works and matches their design.
    1. Encourage students to think about the principles of OOP and to consider how to best encapsulate their code.
    2. If a student's code differs significantly from their design, ask them (carefully) about why they decided to adapt their plan.