CS1331 Homework 04 - Olympics

In this assignment, we will be testing your understanding of the first three SOLID principles: Single responsibility, Open/closed, and the Liskov Substitution Principle.

Download zip

Table of Contents

Introduction

The Olympics are happening (in like two/four years but whatever)! However, the Olympic commission has become wracked with corruption and as a result the event is being terribly mismanaged. This is especially evident in the Java program they’re using to manage the people at the event. As a promising Georgia Tech undergrad, they have hired you to work (for free) to fix their computer system and save the Olympics!

olympic rings

Problem Description

The current codebase for managing the people at the Olympic event violates many of the SOLID principles, namely Single Responsibility, Open/Closed, and Liskov Substitution. Your job is to refactor this code base to conform to these principles. This assignment is fairly open ended, so you have freedom to create new files and name them as you like. Consequently, most of your grade on this assignment will be on your design choices, and your explanation of those design choices.

Background

Before beginning this assignment, it would be wise to familiarize yourself with these three SOLID design principles (you need not worry about Interface Segregation and Dependency Injection for now; those will be covered more in depth in CS 2340). Your lecture notes are a good source of information, but don’t be afraid to branch out and do some of your own research! There are plenty of good and reliable sources out there to learn from, like Wikipedia. To give you a general idea of each principle though, we will summarize them briefly in this section.

Single Responsibility Principle

This principle is fairly intuitive. It basically means that each class should only really be responsible for managing and manipulating its own information, and there shouldn’t be that much information to manage. Essentially, this principle suggests the use of many smaller classes, each with a very specific purpose over the use of larger, broader classes. Doing this helps to make the code more modular, reusable, and extensible.

Open/Closed Principle

The short form of this princple would be, “Open for extension, but closed for modification.” Essentially, it means that when you write a class, you’re done. When you need new features, this means you can’t go back and add code to that class, and this is for good reason. If for every time you needed more features you just tacked them onto the same class, you would soon have a very broad class that is doing too many things. Moreover, requiring everyone on a team to edit the same file makes work a bit of a hassle. Instead, it’s better to close classes for modification, but leave them open for extension. This means that subclassing a class is OK when you need to add more features or change functionality.

Liskov Substitution Principle

This one sounds spooky. but don’t worry, it’s not that bad. The short form of this one is that for anywhere an instance of a super class is expected, an instance of one of its subclasses should be able to be substituted. By, “be able to be substituted,” we mean that when the subclass inherits methods, it does not broaden the preconditions of any of those methods, or relax their postconditions if it overrides them. In plain English, this means that overridden methods or functionalities do not require any more than those in the super class, and promise no less than them. Think back to the Rectangle and Square example from lecture. There, the Square was violating LSP because it relaxed the postconditions (promised less than the superclass’s version) of the setWidth and setHeight methods (that they could be called without modifiying the other variable).

Solution Description

Make sure that you read this whole document before starting! It may also help to review your lecture notes on the SOLID principles discussed in class. Also it will probably help to take a look at the summaries above if you skipped over them.

Athlete.java

EventManager.java

Spectator.java and SuperFan.java

Olympics.java

Javadocs

Checkstyle

As mentioned in the previous homework, you will be running a style checking program on your code. For each violation the tool finds, you will lose one point on your total grade for this assignment.

To make things easier for you in the beginning of the semester, the first few homeworks will have a checkstyle cap, or a maximum amount of points that can be lost to checkstyle. For this homework, the checkstyle cap is 75, meaning you can lose up to 75 points on this assignment due to style errors. As the semester goes on, this cap will increase with each homework and eventually go away. Run checkstyle early, and get in the habit of writing style compliant code the first time. Don’t wait until 5 minutes before the deadline to find out that you have 100+ violations.

Submitting

You should not import any libraries or packages that trivialize the assignment. This includes data structures other than arrays (so no List, Map, Set, etc). If you are unsure of whether something is allowed, ask on Piazza. In general, if something does a large part of the assignment for you, it is probably not allowed. Important: java.util.Arrays is not allowed. However, that is different from a Java array (e.g int[] nums = new int[10]), which is necessary for this assignment.