Lab 2 En

1. Does the following class violate the Single Responsibility Principle? If so, refactor it!

  class Student {
   …
   public void saveStudent();
   public Double calculateMeanGrade();
   public Profile getStudentProfile();
 } 

2. Imagine you have to define a static analysis that captures the violation of Single Responsibility Principle. Which conditions should be fulfilled by a class in order to be detected by this analysis?

3. Based on the next class

 abstract class Vehicle {
    private double peopleCapacity;

    abstract double getSpeed();
    abstract double getAutonomy(); 
    abstract double pressClutch();
  } 

you are required to implement a hierarchy for the next vehicles: Scooter, Tesla and Logan (a gasoline vehicle) and to instantiate the implemented classes.

Logan has back boot capacity and Tesla has back boot capacity as well as a front boot capacity. These vehicles implement an interface that contains int getBootCapacity().

Scooter and Tesla do not have a clutch pedal.

It is forbidden to have duplications among your source code and abstractions that do not fit with the requirements. You are allowed to change the given class, if necessarily.

4. Imagine you have a class ProductsOffer that stores a collection of Products. Each product has name, manufacturer name, color, price, weight and release date. In the first version ProductsOffer provides the next services for filtering the products:

 getByName()
 getByManufacturerName()
 getByColor()
 getByPrice()
 getByWeight()
 getByReleaseDate()

Two weeks later a new method getByNameAndColor() is added inside the class because a client needs to get the products satisfying this new filter.

Two months later a new method getByManufacturerNameAndReleaseDate() is added inside the class because another client needs to get the products satisfying this second filter.

Is ProductsOffer well designed? If it is not, present the reasons and refactor the existing implementation in order to get rid of all the encountered problems.