Skip to content

daschub/05-generic-bounds

Repository files navigation

This is an assignment to the class Programmieren 3 at the University of Applied Sciences Rosenheim.

Assignment 5: Generic bounds

In this assignment we want to deal with generic bounds. Generic bounds are a great possibility to describe constraints of generic classes or methods.

Setup

  1. Create a fork of this repository (button in the right upper corner)
  2. Clone the project (get the link by clicking the green Clone or download button)
  3. Import the project to your IDE (remember the guide in assignment 1)
  4. Validate your environment by running the tests from your IntelliJ and by running gradle test on the command line.

Part 1

First we want to create the model for this assigment:

Model spec

  1. Create the enum PlantColor
  2. Implement the abstract class Plant
  3. Implement the child classes Flower and Shrub
    Remarks: A shrub is always green. A flower mustn't be green but any other color is possible (handle a wrong value in the constructor)
  4. Create tests to ensure that your model classes are correct (e.g. green flowers aren't possible)

Part 2

Now that we've a model we want to implement a PlantBed which takes care of the plants.

PlantBed spec

Implement the class PlantBed as given in the UML. The PlantBed may contain any subclass of Plant but nothing else! (Think of the concept of bounds when you declare the generic!)

Remarks: The method getPlantsByColor is very easy to implement if you think of the filter method of the SimpleList! Remember to create tests for nearly every line you code!

Part 3

Last but not least we'll look at the PECS (Producer Eextends Consumer Super) principle.

Utils spec

  1. Modify the map method in the SimpleList interface according to the PECS principle
  2. Implement the utility method splitBedByColor in a utility class PlantBedUtility
    Side note: why should the class PlantBedUtility be abstract and have a private constructor?
    Remark: the given UML for the utility method does not include any generic bound but you need some (PECS!) because the compilere won't let you implement the method as described in the UML!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages