Design Patterns

 40 Minutes
 20 Questions


This test will assess a candidate's knowledge of technology, design patterns, and their associated creational, structural, and behavioral patterns. The test will include questions related to the various types of design patterns and how they are used in technology. Candidates should be able to explain the differences between creational, structural, and behavioral patterns as well as provide examples of each. Additionally, candidates should be able to identify when a particular pattern is best suited for a given situation.


Example Question:

Multiple-Choice
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;
}
}