Exercises in Programming Style–Things

NOTE : read the rest of the series, or check out the source code.

If you enjoy read­ing these exer­cises then please buy Crista’s book to sup­port her work.


Fol­low­ing on from the last post, we will look at the Things style today.


Style 10 – Things

You may also know this style as OOP.



  • Larg­er prob­lem is decom­posed into things that make sense for the prob­lem domain
  • Each thing is a cap­sule of data that expos­es pro­ce­dures to the rest of the world
  • Data is nev­er accessed direct­ly, only through these pro­ce­dures
  • Cap­sules can re-appro­pri­ate pro­ce­dures defined in oth­er cap­sules


First, we have a thing for stor­ing data from a file:


Then, we anoth­er thing for stor­ing the stop words we’ll deal­ing with lat­er:


Next, we have anoth­er thing that keeps track of the word fre­quen­cies:


Final­ly, we have a thing that con­trols the flow of our appli­ca­tion:


And to tie every­thing togeth­er, we need to con­struct and run the con­troller:




You can find the source code for this exer­cise here.