This is an assignment to the class Programmieren 3 at the University of Applied Sciences Rosenheim.
In this assignment we want to deal with generic bounds. Generic bounds are a great possibility to describe constraints of generic classes or methods.
- Create a fork of this repository (button in the right upper corner)
- Clone the project (get the link by clicking the green Clone or download button)
- Import the project to your IDE (remember the guide in assignment 1)
- Validate your environment by running the tests from your IntelliJ and by running
gradle test
on the command line.
First we want to create the model for this assigment:
- Create the
enum
PlantColor - Implement the
abstract
class Plant - 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) - Create tests to ensure that your model classes are correct (e.g. green flowers aren't possible)
Now that we've a model we want to implement a PlantBed which takes care of the plants.
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!
Last but not least we'll look at the PECS (Producer Eextends Consumer Super) principle.
- Modify the map method in the SimpleList interface according to the PECS principle
- Implement the utility method splitBedByColor in a utility class PlantBedUtility
Side note: why should the class PlantBedUtility beabstract
and have aprivate
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!