O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

We have already seen one possible implementation of the SpeedModel class. Here is another way to do this inside the FactorySpeedModel class: 

public class FactorySpeedModel {  public static SpeedModel generateSpeedModel(  Properties drivingConditions){    //if drivingConditions includes "roadCondition"="Wet"    return new SpeedModelWet(...);    //if drivingConditions includes "roadCondition"="Dry"    return new SpeedModelDry(...);  }  private class SpeedModelWet implements SpeedModel{    public double getSpeedMph(double timeSec, int weightPounds,                               int horsePower){...}  }  private class SpeedModelDry implements SpeedModel{    public double getSpeedMph(double timeSec, int weightPounds,                               int horsePower){...}   }}

We put comments (as pseudo code) and the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required