Question: 1 . ( 1 0 pts ) After reading the code as below, please answer the following questions. Draw the UML diagram for this design

1.(10 pts) After reading the code as below, please answer the following questions. Draw the UML diagram for this design pattern given the java code. Explain the importance of this design pattern.
interface CPU {
void process();
}
interface CPUFactory {
CPU produceCPU();
}
class AMDFactory implements CPUFactory {
public CPU produceCPU(){
return new AMDCPU();
}
}
class IntelFactory implements CPUFactory {
public CPU produceCPU(){
return new IntelCPU();
}
}
class AMDCPU implements CPU {
public void process(){
System.out.println("AMD is processing...");
}
}
class IntelCPU implements CPU {
public void process(){
System.out.println("Intel is processing...");
}
}
class Computer {
CPU cpu;
public Computer(CPUFactory factory){
cpu = factory.produceCPU();
cpu.process();
}
}
public class Client {
public static void main(String[] args){
new Computer(createSpecificFactory());
}
public stic CPUFactory createSpecificFactory(){
int sys =0; // based on specific requirement
if (sys ==0)
return new AMDFactory();
else
return new IntelFactory();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!