Week 2 - Unit Testing, More OOP and Composition

Learning objectives

  • Describe and apply the principles of Unit testing and Test Driven Development
  • Use objects as input and output for functions
  • Recognize how and when to appropriately use const and static class members
  • Use composition to build objects from other objects
  • Trace code that uses pointers and memory addresses

Monday

Tuesday

Wednesday

Thursday

  • Holiday!

Friday

Object Passing & Objects with Arrays

Read 10.3-10.4. These videos help explain them:

Static, Const, and Interacting Objects

Read 10.5-10.6, 10.10 - Static, Const, Interacting Objects.

The book does not have good examples of interacting objects (a Circle that takes a Point as a parameter). review these videos, and the cs162Code samples for those topics:

Do CPPLab - OOThinking.

OODesign

Read 10.7 and 10.11 for general advice about designing objects - I have one extra point to add:

Single Representation: We only want to represent each piece of information once. If you already have a piece of data represented in a class, or the information to calculate it, you should not store it again. For example, in the Circle class, we might have a getArea() function but do not have an area variable. getArea() can calculate the area whenever it is needed by using the radius that we already store. If we stored the area explicitly, it would be much easier to do something dumb like change the radius of the circle and forget to update the area. Only if after testing do we realize the calculation takes an inordinate amount of time (say we need to get a circle's area thousands of times per second) should we worry about explicitly storing the calculated value.

Composition

Read 10.8 about Composition. I think the treatment there is a bit weak, so I also recommend reading learncpp.com Ch 23.1/23.2 about Composition.

This video walks through a sample of using composition.

Pointers Review

Review 11.1-11.2 (which should be a review from CS161). Rewatch this video if you don't feel confident thinking in terms of pointers and memory addresses:

Then read 11.3-11.4 and 11.6-11.7. This material expands on the basics from 161.

Watch these videos (the related code is in the Github repository):

Do the Pointer Worksheet from the Files area in elearn - it is similar to the one from CS161 but has more complex problems. Start by reading the PointerWSExample file - it shows you how you should record the effects of lines of code. Use the PointerWSKey to check your work.

Quiz

Quizzes are time limited (60 minutes). They are open-book (use your book/notes/samples) but are not collaborative (do not discuss them). It covers weeks 1 & 2.

Make sure you block out an hour of uninterrupted time before you start the quiz — you can not pause the timer once you start.

The topics include weeks 1 and 2 up through OODesign - Composition and pointers are not included.

To practice, go to the Resource Links and look for "Practice Quiz Questions".