O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Simple Example That Makes You Think

Let’s look at an example in Java. Listing 2-1 shows a simple Java class with several clues about its intent in the way it is constructed. Consider the ScoreWatcher class that is part of a system to track sports scores. It encapsulates the function of obtaining the scores from a news feed.

Listing 2-1: A simple Java class to demonstrate intentional construction

class ScoreWatcher {  private final NewsFeed feed;  private int pollFrequency; // Seconds  public ScoreWatcher(NewsFeed feed, int pollFrequency) {    this.feed = feed;    this.pollFrequency = pollFrequency;  }  public void setPollFrequency(int pollFrequency) {    this.pollFrequency = pollFrequency;  }  public int getPollFrequency() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required