Question: a ) Identify the pattern present in the code and name the roles of each class in the code. b ) Draw a class diagram
a Identify the pattern present in the code and name the roles of each class in the code. b Draw a class diagram connecting the classes. c Briefly describe two scenarios when you want to use this design pattern.
AAjava
public interface AA
void fooSO so;
void fooSE se;
void fooCO co;
App.java
public class App
public static void mainString args
UN co new CO
new SEnew SO new SO new SO
new SEnew SO new SO new SO
;
coxxnew BB;
coxxnew DD;
coxxnew CC;
BBjava
public class BB implements AA
@Override
public void fooSO so
System.out.printlnGreetings so;
@Override
public void fooSE se
Do nothing
@Override
public void fooCO co
Do nothing
CCjava
@Override
public void fooSO so
Do nothing
@Override
public void fooSE se
Do nothing
@Override
public void fooCO co
System.out.printlnGood to see you co;
COjava
public class CO extends UN
public COUN children
superchildren;
@Override
public void xxAA aa
aafoothis;
super.xxaa;
@Override
public String toString
return "commander";
DDjava
public class DD implements AA
@Override
public void fooSO so
Do nothing
@Override
public void fooSE se
System.out.printlnHello se;
@Override
public void fooCO co
Do nothing
SEjava
public class SE extends UN
public SEUN children
superchildren;
@Override
public void xxAA aa
aafoothis;
super.xxaa;
@Override
public String toString
return "sergeant";
SOjava
public class SO extends UN
public SOUN children
superchildren;
@Override
public void xxAA aa
aafoothis;
super.xxaa;
@Override
public String toString
return "soldier";
UNjava
import java.util.Arrays;
public abstract class UN
private UN children;
public UNUN children
this.children children;
public void xxAA aa
Arrays.streamchildrenforEachchild child.xxaa;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
