Open
Description
The "bad" example seems to apply the rule very well. The owner knows nothing about the Engine, just the Car. Moreover, the "good" example is also fine, though the method name suggests that the engine should be started in the Car.
A violation would be as follows:
public class Owner {
private Car car;
public Owner() {
this.car = new Car();
}
public void startCar() {
car.getEngine().start();
}
}
public class Car {
private Engine engine;
public Car() {
this.engine = new Engine();
}
public Engine getEngine(){
return engine;
}
public void start() {
engine.start();
}
}
public class Engine {
public void start() {
System.out.println("Starting engine");
}
}
Metadata
Metadata
Assignees
Labels
No labels