2 Problem description In this labwork you are expected to implement a program that builds a computer for different purposes using Template Method pattern. Your program needs to able to build two types of computers which is Gaming and Office. CPU, Memory and type of storage depends on the computer type. For a gaming computer you need to put: ∗ High-end multi-core cpu ∗ High-clock speed memory ∗ SSD storage For an office computer you need to put: ∗ Low-end dual-core cpu ∗ Energy-efficient memory ∗ Energy-efficient HDD However, way you build a computer is a set of pre-determined steps: ∗ Plug CPU ∗ Plug Memory ∗ Plug Storage ∗ Plug peripherals (which are common for both type of computer)
3 Measure of success You are expected to implement necessary classes for this example using Template Method Pattern.
abstract class Computer {
abstract void plugCPU();
abstract void plugMemory();
abstract void plugStorage();
}
class GamingComputer extends Computer {
@Override
void plugCPU() {
System.out.println(" * High-end multi-core cpu");
}
@Override
void plugMemory() {
System.out.println(" * High-clock speed memory");
}
@Override
void plugStorage() {
System.out.println(" ∗ SSD storage");
}
}
class OfficeComputer extends Computer {
@Override
void plugCPU() {
System.out.println("∗ Low-end dual-core cpu");
}
@Override
void plugMemory() {
System.out.println("∗ Energy-efficient memory");
}
@Override
void plugStorage() {
System.out.println("∗ Energy-efficient HDD");
}
}
Comments
Leave a comment