Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

팩토리 메서드 패턴은 어떻게 활용할 수 있을까요?, if-else를 쓰지 않을 방법은 없을까요? #27

Open
tlarbals824 opened this issue Jul 29, 2023 · 1 comment

Comments

@tlarbals824
Copy link
Member

팩토리 메서드 패턴을 실제 어떻게 활용할 수 있을까요?
if-else 를 지양하는것이 좋다고 알아서, 아예 쓰지 않고 다양한 객체를 생성해내는 방법은 없을까요? ex) Map 에 매핑 정보를 저장

@gzgzg2
Copy link
Contributor

gzgzg2 commented Jul 29, 2023

특정 타입에 따라 분기가 필요할 때 스프링의 빈팩토리와 의존 주입을 활용해서 구현할 수 있을 것 같아요 ~

  • 분기가 필요한 행위를 추상화하여 구현체를 스프링 Bean으로 만들기
    image
    image

  • enum으로 생성한 빈 name 관리하기 (빈의 이름이 Map의 Key가 됩니다.)
    image

  • 타입에 맞는 행위 꺼내기
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants