← Learning

Scala Iteration 3

< Iteration 2: Starting with Functional Concepts

Object Oriented Programming in Scala

This covers chapters 8-11 in the O’Reilly book.

Given the following sealed trait:

sealed trait Values

Define case classes Numbers (which holds an Int), Strings (which holds a String), and UnaryFunction (which holds a function that takes in Any and returns Any). Create an interpret function that prints out information about what was passed in: it should have different messages printed out for Strings, Unary Functions, Numbers, and Numbers less than ten. Print out the contents of the case class as well.

Create an abstract class. Create two different implementations of that class, with at least one shared method and one unique method per implementation. Create a factory to generate instances of the abstract class. This can represent anything, so long as it fits the given constraints.

For example, you might create an abstract class Bicycle, with methods ride(distance: Int) and checkTires(). Implementations might include MountainBike with some method getGear(), and DirtBike, with method getFuel().

Unit Testing

Complete the Specs2 tutorial provided.

If you haven’t already, now is a great time to figure out how to use .gitignore files. This will allow you to ignore paths/file types that you do not want git to keep track of - for example the target/ path you saw in the Specs2 tutorial.

Write unit tests around your abstract class code from this iteration.

You are expected to write Specs2 tests for all of your code after this point.

Milestone Project

Create tests around your library functions from last iteration. If you were thoughtful when creating your mock data last time, this should be fairly simple. As your project grows, you will need to add tests and ensure proper coverage.


Iteration 4: Scala’s Type System >