Table Of Contents

Previous topic

Modules, packages, oh my!!

Next topic

Candidates, of course

This Page

OO Design and Refactoring

Real World Objects

In this section, we create classes that model the real world of elections. These classes are intended to serve as more intuitive containers for data transformations and complex bits of logic currently scattered across our application.

The goal is to hide complexity behind simple interfaces.

We perform these refactorings in a step-by-step fashion and attempt to write tests before the actual code.

So how do we start modeling our domain? We clearly have races and candidates, which seem like natural...wait for it... “candidates” for model classes. We also have county-level results associated with each candidate.

Let’s start by creating Candidate and Race classes with some simple behavior. These classes will eventually be our workhorses, handling most of the grunt work needed to produce the summary report. But let’s start with the basics.