a bit of Interface Segregation Principle
a bit of Interface Segregation Principle
This commit is contained in:
parent
ed847ee613
commit
35d570241a
|
@ -1,6 +1,6 @@
|
||||||
package cat.hack3.codingtests.marsrover;
|
package cat.hack3.codingtests.marsrover;
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation;
|
import cat.hack3.codingtests.marsrover.api.RotableRover;
|
||||||
import cat.hack3.codingtests.marsrover.api.cartography.Coordinates;
|
import cat.hack3.codingtests.marsrover.api.cartography.Coordinates;
|
||||||
import cat.hack3.codingtests.marsrover.api.cartography.Direction;
|
import cat.hack3.codingtests.marsrover.api.cartography.Direction;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class RoverActionReporter {
|
||||||
logger.info(movementReport);
|
logger.info(movementReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportRotation(Rotation rotation, Direction newDirection) {
|
public void reportRotation(RotableRover.Rotation rotation, Direction newDirection) {
|
||||||
logger.info(String.format(ROTATION_REPORT_MESSGE,
|
logger.info(String.format(ROTATION_REPORT_MESSGE,
|
||||||
rotation, newDirection));
|
rotation, newDirection));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package cat.hack3.codingtests.marsrover.api;
|
||||||
|
|
||||||
|
import cat.hack3.codingtests.marsrover.api.cartography.Coordinates;
|
||||||
|
|
||||||
|
public interface LocateableRover {
|
||||||
|
Coordinates getCurrentCoordinates();
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package cat.hack3.codingtests.marsrover.api;
|
||||||
|
|
||||||
|
import cat.hack3.codingtests.marsrover.api.cartography.Direction;
|
||||||
|
|
||||||
|
public interface RiderRover {
|
||||||
|
void moveTowards(Direction direction);
|
||||||
|
Direction getCurrentDirection();
|
||||||
|
}
|
|
@ -1,19 +1,9 @@
|
||||||
package cat.hack3.codingtests.marsrover.api;
|
package cat.hack3.codingtests.marsrover.api;
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.cartography.Coordinates;
|
|
||||||
import cat.hack3.codingtests.marsrover.api.cartography.Direction;
|
import cat.hack3.codingtests.marsrover.api.cartography.Direction;
|
||||||
import cat.hack3.codingtests.marsrover.api.cartography.PlanetMap;
|
import cat.hack3.codingtests.marsrover.api.cartography.PlanetMap;
|
||||||
|
|
||||||
public interface RotableRiderRover {
|
public interface RotableRiderRover extends RotableRover, RiderRover, LocateableRover {
|
||||||
enum Rotation {LEFT, RIGHT}
|
|
||||||
|
|
||||||
void moveTowards(Direction direction);
|
|
||||||
|
|
||||||
void rotateTowards(Rotation rotation);
|
|
||||||
|
|
||||||
Coordinates getCurrentCoordinates();
|
|
||||||
|
|
||||||
Direction getCurrentDirection();
|
|
||||||
|
|
||||||
interface Provider {
|
interface Provider {
|
||||||
RotableRiderRover provideWith(PlanetMap map, Direction startingDirection);
|
RotableRiderRover provideWith(PlanetMap map, Direction startingDirection);
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package cat.hack3.codingtests.marsrover.api;
|
||||||
|
|
||||||
|
public interface RotableRover {
|
||||||
|
enum Rotation {LEFT, RIGHT}
|
||||||
|
|
||||||
|
void rotateTowards(Rotation rotation);
|
||||||
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
package cat.hack3.codingtests.marsrover.commands;
|
package cat.hack3.codingtests.marsrover.commands;
|
||||||
|
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
import cat.hack3.codingtests.marsrover.api.RiderRover;
|
||||||
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
||||||
|
|
||||||
public class MoveBackwardsCommand implements RoverCommand {
|
public class MoveBackwardsCommand implements RoverCommand {
|
||||||
private final RotableRiderRover rover;
|
private final RiderRover rover;
|
||||||
|
|
||||||
public MoveBackwardsCommand(RotableRiderRover rover) {
|
public MoveBackwardsCommand(RiderRover rover) {
|
||||||
this.rover = rover;
|
this.rover = rover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package cat.hack3.codingtests.marsrover.commands;
|
package cat.hack3.codingtests.marsrover.commands;
|
||||||
|
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
import cat.hack3.codingtests.marsrover.api.RiderRover;
|
||||||
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
||||||
|
|
||||||
public class MoveForwardCommand implements RoverCommand {
|
public class MoveForwardCommand implements RoverCommand {
|
||||||
private final RotableRiderRover rover;
|
private final RiderRover rover;
|
||||||
|
|
||||||
public MoveForwardCommand(RotableRiderRover rover) {
|
public MoveForwardCommand(RiderRover rover) {
|
||||||
this.rover = rover;
|
this.rover = rover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package cat.hack3.codingtests.marsrover.commands;
|
package cat.hack3.codingtests.marsrover.commands;
|
||||||
|
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
import cat.hack3.codingtests.marsrover.api.RotableRover;
|
||||||
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation.LEFT;
|
import static cat.hack3.codingtests.marsrover.api.RotableRover.Rotation.LEFT;
|
||||||
|
|
||||||
public class TurnLeftCommand implements RoverCommand {
|
public class TurnLeftCommand implements RoverCommand {
|
||||||
private final RotableRiderRover rover;
|
private final RotableRover rover;
|
||||||
|
|
||||||
public TurnLeftCommand(RotableRiderRover rover) {
|
public TurnLeftCommand(RotableRover rover) {
|
||||||
this.rover = rover;
|
this.rover = rover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package cat.hack3.codingtests.marsrover.commands;
|
package cat.hack3.codingtests.marsrover.commands;
|
||||||
|
|
||||||
|
|
||||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
import cat.hack3.codingtests.marsrover.api.RotableRover;
|
||||||
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
import cat.hack3.codingtests.marsrover.api.commands.RoverCommand;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation.RIGHT;
|
import static cat.hack3.codingtests.marsrover.api.RotableRover.Rotation.RIGHT;
|
||||||
|
|
||||||
public class TurnRightCommand implements RoverCommand {
|
public class TurnRightCommand implements RoverCommand {
|
||||||
private final RotableRiderRover rover;
|
private final RotableRover rover;
|
||||||
|
|
||||||
public TurnRightCommand(RotableRiderRover rover) {
|
public TurnRightCommand(RotableRover rover) {
|
||||||
this.rover = rover;
|
this.rover = rover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue