Skip to content

Instantly share code, notes, and snippets.

@VintageAppMaker
Created March 4, 2018 03:03
Show Gist options
  • Save VintageAppMaker/aff423d86efd5bb3298c777830e8af77 to your computer and use it in GitHub Desktop.
Save VintageAppMaker/aff423d86efd5bb3298c777830e8af77 to your computer and use it in GitHub Desktop.
/*
* 제목:inner Class를 이용한 동적함수처리
* 작성자: 박성완(adsloader@naver.com)
* 목적 : 예제
* */
import java.util.HashMap;
class Event{
public int STATE = 0;
public Event (int i ){STATE = i;}
}
public class Main {
public static int START = 0;
public static int STOP = 1;
public static int PAUSE = 2;
//----------------------------------------------------
public void OnStart(Event e)
{
System.out.println("Start");
}
public void OnStop(Event e)
{
System.out.println("Stop");
}
public void OnPause(Event e)
{
System.out.println("Pause");
}
//----------------------------------------------------
HashMap m = new HashMap();
public void Process(Event e)
{
FSM f = (FSM)m.get(e.STATE);
f.Execute(e);
}
public Main()
{
initProcess();
}
public void initProcess()
{
m.put(START,
new FSM(){
public void Execute(Event e){
OnStart(e);
};
}
);
m.put(STOP,
new FSM(){
public void Execute(Event e){
OnStop(e);
};
}
);
m.put(PAUSE,
new FSM(){
public void Execute(Event e){
OnPause(e);
};
}
);
}
class FSM
{
public void Execute(Event e){};
}
//-----------------------------------------------------
static public void main(String[] args)
{
Main o = new Main();
o.Process(new Event(Main.START));
o.Process(new Event(Main.STOP));
o.Process(new Event(Main.PAUSE));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment