Skip to content

Commit

Permalink
[Strategy Pattern] example 02
Browse files Browse the repository at this point in the history
  • Loading branch information
jihunparkme committed Dec 1, 2022
1 parent b31151e commit ae539d6
Showing 1 changed file with 60 additions and 0 deletions.
Expand Up @@ -44,4 +44,64 @@ void strategyV1() {
ContextV1 context2 = new ContextV1(strategyLogic2);
context2.execute();
}

/**
* 전략 패턴 익명 내부 클래스1
*/
@Test
void strategyV2() {
Strategy strategyLogic1 = new Strategy() {
@Override
public void call() {
log.info("비즈니스 로직1 실행");
}
};
log.info("strategyLogic1={}", strategyLogic1.getClass());
ContextV1 context1 = new ContextV1(strategyLogic1);
context1.execute();

Strategy strategyLogic2 = new Strategy() {
@Override
public void call() {
log.info("비즈니스 로직2 실행");
}
};
log.info("strategyLogic2={}", strategyLogic2.getClass());
ContextV1 context2 = new ContextV1(strategyLogic2);
context2.execute();
}

/**
* 전략 패턴 익명 내부 클래스2
*/
@Test
void strategyV3() {
ContextV1 context1 = new ContextV1(new Strategy() {
@Override
public void call() {
log.info("비즈니스 로직1 실행");
}
});
context1.execute();

ContextV1 context2 = new ContextV1(new Strategy() {
@Override
public void call() {
log.info("비즈니스 로직2 실행");
}
});
context2.execute();
}

/**
* 전략 패턴, 람다
*/
@Test
void strategyV4() {
ContextV1 context1 = new ContextV1(() -> log.info("비즈니스 로직1 실행"));
context1.execute();

ContextV1 context2 = new ContextV1(() -> log.info("비즈니스 로직2 실행"));
context2.execute();
}
}

0 comments on commit ae539d6

Please sign in to comment.