SlideShare a Scribd company logo
1 of 14
백엔드 스터디
Design Patterns
Factory Pattern
참고 도서
Head First Design Patterns자바 객체지향 디자인 패턴
● 우리가 사용하는 ‘new’
● Factory Pattern
● Simple Factory
● Factory Method Pattern
● Dependency Inversion Principle(DI)
● Abstract Factory Pattern
우리가 사용하는 ‘new’
- new 를 사용하는 것은 구상 클래스의 인스턴스를 만드는
것
- 자바에서 객체를 생성할 때는 new 를 사용한다.
- Pizza pizza = new ChessesPizza();
- ‘변화' 되는 것 때문에 new 를 사용하는데 있어서 조심해야
함
- 바뀔 수 있는 부분을 찾아내서 바뀌지 않는 부분과 분리하
는 원칙을 생각해보자.
Factory Pattern
- 팩토리를 쓰면 객체 생성을 캡슐화 할 수 있다.
- 모든 팩토리 패턴에서는 애플리케이션의 구상클래스에 대
한 의존성을 줄여줌으로써 느슨한 결합을 도와준다.
- 팩토리는 구상 클래스가 아닌 추상 클래스/인터페이스에
맞춰서 코딩할 수 있게 한다.
Simple Factory - 엄밀하게 말하자면 디자인 패턴은
아님.
Factory Method Pattern
- 상속을 활용
- 객체를 생성하기 위한 인터페이스를 정의하는데
어떤 클래스의 인스턴스를 만들지는 서브클래스에
서 결정하게 만든다. (객체 생성이 서브클래스에게
위임)
- 클래스의 인스턴스를 만드는 일을 서브클래스에게
맡김
Factory Method Pattern
Dependency Inversion Principle - 의존성 뒤집기 원칙
- 추상화된 것에 의존하도록 만들자. 구상 클래스에 의존하도록
만들지 않도록 한다.
- “특정 구현이 아닌 인터페이스에 맞춰서 프로그래밍 한다” 는 원
칙보다 추상화를 더 많이 강조
- 고수준의 구성요소가 저수준 구성요소에 의존하면 안 된다. (‘고
수준' 구성요소는 다른 ‘저수준' 구성요소에 의해 정의되는 행동이 들어
있는 구성요소를 말함)
- 구상 클래스처럼 구체적인 것이 아닌 추상 클래스나 인터페이스
Abstract Factory Pattern
- 객체의 구성을 활용
- 객체 생성이 팩토리 인터페이스에서 선언한 메소드들에서
구현
- 인터페이스를 이용하여 서로 연관된, 또는 의존하는 객체
를 구상 클래스를 지정하지 않고도 생성할 수 있다.
- 구상 클래스에 직접 의존하지 않고도 서로 관련된 객체들
로 이루어진 제품군을 만들기 위한 용도로 사용
백엔드 스터디 Design patterns

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

백엔드 스터디 Design patterns

  • 2. 참고 도서 Head First Design Patterns자바 객체지향 디자인 패턴
  • 3. ● 우리가 사용하는 ‘new’ ● Factory Pattern ● Simple Factory ● Factory Method Pattern ● Dependency Inversion Principle(DI) ● Abstract Factory Pattern
  • 4. 우리가 사용하는 ‘new’ - new 를 사용하는 것은 구상 클래스의 인스턴스를 만드는 것 - 자바에서 객체를 생성할 때는 new 를 사용한다. - Pizza pizza = new ChessesPizza(); - ‘변화' 되는 것 때문에 new 를 사용하는데 있어서 조심해야 함 - 바뀔 수 있는 부분을 찾아내서 바뀌지 않는 부분과 분리하 는 원칙을 생각해보자.
  • 5. Factory Pattern - 팩토리를 쓰면 객체 생성을 캡슐화 할 수 있다. - 모든 팩토리 패턴에서는 애플리케이션의 구상클래스에 대 한 의존성을 줄여줌으로써 느슨한 결합을 도와준다. - 팩토리는 구상 클래스가 아닌 추상 클래스/인터페이스에 맞춰서 코딩할 수 있게 한다.
  • 6. Simple Factory - 엄밀하게 말하자면 디자인 패턴은 아님.
  • 7. Factory Method Pattern - 상속을 활용 - 객체를 생성하기 위한 인터페이스를 정의하는데 어떤 클래스의 인스턴스를 만들지는 서브클래스에 서 결정하게 만든다. (객체 생성이 서브클래스에게 위임) - 클래스의 인스턴스를 만드는 일을 서브클래스에게 맡김
  • 9.
  • 10. Dependency Inversion Principle - 의존성 뒤집기 원칙 - 추상화된 것에 의존하도록 만들자. 구상 클래스에 의존하도록 만들지 않도록 한다. - “특정 구현이 아닌 인터페이스에 맞춰서 프로그래밍 한다” 는 원 칙보다 추상화를 더 많이 강조 - 고수준의 구성요소가 저수준 구성요소에 의존하면 안 된다. (‘고 수준' 구성요소는 다른 ‘저수준' 구성요소에 의해 정의되는 행동이 들어 있는 구성요소를 말함) - 구상 클래스처럼 구체적인 것이 아닌 추상 클래스나 인터페이스
  • 11.
  • 12.
  • 13. Abstract Factory Pattern - 객체의 구성을 활용 - 객체 생성이 팩토리 인터페이스에서 선언한 메소드들에서 구현 - 인터페이스를 이용하여 서로 연관된, 또는 의존하는 객체 를 구상 클래스를 지정하지 않고도 생성할 수 있다. - 구상 클래스에 직접 의존하지 않고도 서로 관련된 객체들 로 이루어진 제품군을 만들기 위한 용도로 사용