Back-end/Java, Kotlin

디자인패턴 중.. State

philo0407 2020. 12. 17. 23:57

 

쉬워 보이는 State 공부하고 잇었다..

 

class ModeStateLight implements ModeState {
	
	static {
		out.println("static ");
	}
	
	{
		out.println("before constructor :" + this);
	}
	
	ModeStateLight() {
		out.println("call constructor : "+ this);
	}

	@Override
	public void toggle(ModeSwitch modeSwitch) {
		out.println("Ligth");
		
		modeSwitch.setState(new ModeStateNight());
	}
}

 

위 처럼 입력하면 아래와 같은 출력이 나온다.

static 
before constructor :DesignPattern.ModeStateLight@76ccd017
call constructor : DesignPattern.ModeStateLight@76ccd017
Ligth

 

 

 

 

m.blog.naver.com/PostView.nhn?blogId=2feelus&logNo=220576845725&proxyReferer=https:%2F%2Fwww.google.com%2F

 

Java에서 protected 의 의미와 용도

1. Java의 접근자(modifier)들 Java 의 필드와 메소드들에 대한 접근 권한 제어를 modifier라고 한다. pr...

blog.naver.com

아직 설계가 덜 되었음을 나타내는 용도라고 한다!