Design Patterns - Sample Interview Question (Junior Level)

Which of the following design patterns represents the code below?

//Vehicle.java
package com.lugo.model;

public interface Vehicle {
public void initialEngine();
public void drive();

}

//Car.java
package com.lugo.model;

public class Car implements Vehicle {

int numberOfSeats;
public Car(int numOfSeats){
numberOfSeats = numOfSeats;
}
@Override
public void initialEngine() {
// car initial engine operations

}

@Override
public void drive() {
// car is driving 

}
}

//Bus.java
package com.lugo.model;

public class Bus implements Vehicle {
int numberOfSeats;
public Bus(int numOfSeats){
numberOfSeats = numOfSeats;
}

@Override
public void initialEngine() {
// bus initial engine operations

}

@Override
public void drive() {
// bus is driving 

}
}

//VehiclesFactory.java
package com.lugo.model;

import java.util.HashMap;

public class VehiclesFactory {

private static final HashMap<VehicleType,Vehicle> vehicles = new HashMap<VehicleType,Vehicle>();

public static Vehicle getVehicle(VehicleType type) {
Vehicle vehicleImpl = vehicles.get(type);

if (vehicleImpl == null) {
if (type.equals(VehicleType.BUS)) {
vehicleImpl = new Bus(40);
} else if (type.equals(VehicleType.CAR)) {
vehicleImpl = new Car(5);
}
vehicles.put(type, vehicleImpl);
}
return vehicleImpl;
}
public static enum VehicleType{
BUS,CAR;
}
}

  1. Adapter
  2. Composite
  3. Proxy
  4. Flyweight
  5. Facade
Tests in Design Patterns for Juniors

Test Name Difficulty Time (minutes) No. of Questions
Design Patterns Online Test for Juniors Design Patterns Junior 40 20

More Specific Tests in Design Patterns for Juniors

Test Name Difficulty Time (Minutes) No. of Questions
Design-Patterns-Creational-patterns Online Test for Juniors Design Patterns - Creational patterns Junior 20 10
Design-Patterns-Structural-patterns Online Test for Juniors Design Patterns - Structural patterns Junior 20 10