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
Schedule
Day 1
Day 2
- Objects, Functions, & Arrays
- Static, Const, Interacting Objects
- CPPLab - OOThinking
Day 3
Day 4
- Composition
- CPPLab - Composition
Source Control and Git
Source control is going to take you a while to master—don't worry about doing it all this week. Watch the videos and at least work through part 1 of this Git Tutorial, which will walk you through making your own clone of the CS162 repository.
These videos introduce the basic idea behind source control, what git is, and how we will use it:
None of these are required reading, but if you want to learn more about git, here are some good references:
Git Extra Info
Visual Git Reference
Learn Git Branching
Pro Git Book
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 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.