Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spring-toby/java-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
// https://mvnrepository.com/artifact/com.h2database/h2
testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.javabom.toby.chapter1.pattern.전략_패턴;

/**
* Created by jyami on 2020/11/01
*/
public interface ConnectionManager {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.javabom.toby.chapter1.pattern.전략_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class DConnectionManager implements ConnectionManager{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.javabom.toby.chapter1.pattern.전략_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class NConnectionManager implements ConnectionManager {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.javabom.toby.chapter1.pattern.전략_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class UserDao {

public UserDao(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
}

private final ConnectionManager connectionManager;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.javabom.toby.chapter1.pattern.전략_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class UserDaoTest {
public static void main(String[] args) {
/**
* 변경되는 부분 : ConnectionManager > 인터페이스로 제공
* Client에서 원하는 구현체를 선택해서 사용할 수 있게 한다: UserDao에서 사용할 ConnectionManager 구현 클래스를 결정한다.
* 런타임에 오브젝트끼리 관계를 맺게 한다.
*/
ConnectionManager dConnectionManager = new DConnectionManager();
UserDao userDao = new UserDao(dConnectionManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.javabom.toby.chapter1.pattern.템플릿_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class SubWithHook extends Super{

@Override
protected void hookMethod() {
super.hookMethod();
System.out.println("선택적으로 오버라이드 가능한 훅 메서드 : 오버라이드해서 사용");
}

@Override
public void abstractMethod() {
System.out.println("SubWithHook 클래스에서 구현한 메서드");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.javabom.toby.chapter1.pattern.템플릿_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/

public class SubWithoutHook extends Super {
@Override
public void abstractMethod() {
System.out.println("슈퍼클래스의 기능을 오버라이드하거나 구현해서 특정 기능으로 구현한다.");
System.out.println("SubWithoutHook 클래스에서 구현한 메서드");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.javabom.toby.chapter1.pattern.템플릿_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public abstract class Super {

protected void hookMethod(){
System.out.println("선택적으로 오버라이드 가능한 훅 메서드");
}

public abstract void abstractMethod();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.javabom.toby.chapter1.pattern.팩토리_메소드;

/**
* Created by jyami on 2020/11/01
*/
public class Card {

private final CardType cardType;

private Card(CardType cardType) {
this.cardType = cardType;

}

public enum CardType {
LOTTE, HYUNDAI
}


public static Card ofLotte() {
return new Card(CardType.LOTTE);
}

public static Card ofHyundai() {
return new Card(CardType.HYUNDAI);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.javabom.toby.chapter1.pattern.팩토리_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class DeluxePizza extends Pizza{

@Override
protected Pizza getPizza() {
return new DeluxePizza();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.javabom.toby.chapter1.pattern.팩토리_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class HamAndMushroomPizza extends Pizza {

@Override
protected Pizza getPizza() {
return new SeafoodPizza();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.javabom.toby.chapter1.pattern.팩토리_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public abstract class Pizza {

protected abstract Pizza getPizza();

public void eat() {
Pizza pizza = this.getPizza();
System.out.println(pizza);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.javabom.toby.chapter1.pattern.팩토리_메소드_패턴;

/**
* Created by jyami on 2020/11/01
*/
public class SeafoodPizza extends Pizza {

@Override
public Pizza getPizza() {
return new SeafoodPizza();
}

}