Question: Which Pattern is used in the following code? ( Tip: What happens in the application during the test run? See TestRun Class ) public interface

Which Pattern is used in the following code? (Tip: What happens in the application during the test run? See TestRun Class)
public interface Pos { void action(CoCo c, String n); } public class Pos1 implements Pos { @Override public void action(CoCo c, String n){ System.out.println(n +"-"+1); c.me(new Pos2()); }} public class Pos2 implements Pos { @Override public void action(CoCo c, String n){ System.out.println(n +"-"+2); c.me(new Pos1()); }} public class CoCo { private Pos m; CoCo(){ this.m(new Pos1()); } void me(Pos n){ m = n; } public void exec(String st){ m.action(this, st); }} public class TestRun { public static void main(String[] args){ CoCo sc = new CoCo(); sc.exec("HelloWorld"); sc.exec("HelloWorld"); sc.exec("HelloWorld"); sc.exec("HelloWorld"); }}
Adapter Pattern
Decorator Pattern
Command Pattern
State Pattern
Proxy Pattern
Composite Pattern
Iterator Pattern
Template Pattern
Facade Pattern

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!