update solid ex
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.l;
|
||||
|
||||
public interface Car {
|
||||
|
||||
void turnOnEngine();
|
||||
void accelerate();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.l;
|
||||
|
||||
public class ElectricCar implements Car {
|
||||
|
||||
public void turnOnEngine() {
|
||||
throw new AssertionError("I don't have an engine!");
|
||||
}
|
||||
|
||||
public void accelerate() {
|
||||
//this acceleration is crazy!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.l;
|
||||
|
||||
public class Engine {
|
||||
|
||||
public void on(){
|
||||
//vroom.
|
||||
}
|
||||
|
||||
public void powerOn(int amount){
|
||||
//do something
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.l;
|
||||
|
||||
public class MotorCar implements Car {
|
||||
|
||||
private Engine engine;
|
||||
|
||||
//Constructors, getters + setters
|
||||
|
||||
public void turnOnEngine() {
|
||||
//turn on the engine!
|
||||
engine.on();
|
||||
}
|
||||
|
||||
public void accelerate() {
|
||||
//move forward!
|
||||
engine.powerOn(1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user