SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Scala - 트레이트
Real-Time Mobile Messaging Team.
Kim Changkyu
트레이트란?
 자바의 인터페이스기능을 확장한 개념.
 스칼라에서 클래스는 1개만 상속 트레이트는 다중상속
 메소드와 필드 구현을 할 수 있다.
 레이어링을 통하여 상속관계의 트레이트를 호출 할 수 있다.
 인스턴스를 생성할 때에 트레이트를 추가할 수 있다.
Trait 기본 사용법
Trait 다중 구현
 With키워들를 사용해 다중 구현을 할 수 있음.
구현이 있는 Trait
 이때 Trait을 추가할 때에 메서드가 상속되는 것을 ‘믹스인’이라고 한다.
생성시 Trait추가
 빈 메서드가 의미가 없어 보일 수 있겠지만, 생성할때 믹스인을 할 수 있다.
생성시 Trait추가
 생성시 Logged를 상속받은 Trait을 추가함으로서 ‘믹스인'이 일어나고,
 Log를 오버라이드 해버린다.
Layered Trait
 Trait서로를 호출하는 여러 Trait을 추가할 수 있다.
 이는 단계별로 어떤 값을 변화할때 유용하다.
Layered Trait
Layered Trait
추상메서드 오버라이딩
이곳에서 Logged의 log가
추상메서드였다면,
Super.log를 사용하지 못함.
추상 필드 오버라이드
 상속을 받은 클래스에서 오버라이딩 해야함.
Trait 생성 순서
1. 슈퍼클래스 생성자
2. 트레이트 생성자
 왼쪽에서 오른쪽 순서대로 실행
 각 트레이트에서 부모가 먼서 생성
 여러 트레이트가 공통의 부모를 공유하면, 중복해서 생서하지는 않음.
3. 클래스의 생성자
4. 서브 클래스 생성자
추상필드 초기화
 Trait생성 순서에 따라 뒤에서 선언하게 되면 CompileErr가 난다.
 따라서 앞에서 미리 선언하거나, Lazy를 통하여 우회하면 된다.
클래스 확장
 드물게 Class를 확장하는 Trait이 있다.
 해당 Trait을 확장하는 Class는 Trait의 Super Class가 Super Class가 된다.
 Class를 확장하는 Trait을 상속받는 Trait/Class에 또다른 클래스를 상속 받을수
있다.
단, 이때는 서로 부모자식 관계로 이어져야 한다.
Trait 셀프 타입
 This:[type] => 로 시작
 [type]을 상속한 클래스만 해당 Trait을 상속받을수 있음.
 [type]대신 구조적 타입을 지정할 수 있음.
Trait, JVM에서는 어떤일이…
 Trait -> Java Interface로 변환된다.
 구현이 있는 Trait은 해당 메서드를 Companion Class에서 Static으로 정의된다.
 필드는 추상 getter/setter로 대체된다.

Mais conteúdo relacionado

Destaque

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
 

Destaque (20)

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
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Scala 트레이트

  • 1. Scala - 트레이트 Real-Time Mobile Messaging Team. Kim Changkyu
  • 2. 트레이트란?  자바의 인터페이스기능을 확장한 개념.  스칼라에서 클래스는 1개만 상속 트레이트는 다중상속  메소드와 필드 구현을 할 수 있다.  레이어링을 통하여 상속관계의 트레이트를 호출 할 수 있다.  인스턴스를 생성할 때에 트레이트를 추가할 수 있다.
  • 4. Trait 다중 구현  With키워들를 사용해 다중 구현을 할 수 있음.
  • 5. 구현이 있는 Trait  이때 Trait을 추가할 때에 메서드가 상속되는 것을 ‘믹스인’이라고 한다.
  • 6. 생성시 Trait추가  빈 메서드가 의미가 없어 보일 수 있겠지만, 생성할때 믹스인을 할 수 있다.
  • 7. 생성시 Trait추가  생성시 Logged를 상속받은 Trait을 추가함으로서 ‘믹스인'이 일어나고,  Log를 오버라이드 해버린다.
  • 8. Layered Trait  Trait서로를 호출하는 여러 Trait을 추가할 수 있다.  이는 단계별로 어떤 값을 변화할때 유용하다.
  • 11. 추상메서드 오버라이딩 이곳에서 Logged의 log가 추상메서드였다면, Super.log를 사용하지 못함.
  • 12. 추상 필드 오버라이드  상속을 받은 클래스에서 오버라이딩 해야함.
  • 13. Trait 생성 순서 1. 슈퍼클래스 생성자 2. 트레이트 생성자  왼쪽에서 오른쪽 순서대로 실행  각 트레이트에서 부모가 먼서 생성  여러 트레이트가 공통의 부모를 공유하면, 중복해서 생서하지는 않음. 3. 클래스의 생성자 4. 서브 클래스 생성자
  • 14. 추상필드 초기화  Trait생성 순서에 따라 뒤에서 선언하게 되면 CompileErr가 난다.  따라서 앞에서 미리 선언하거나, Lazy를 통하여 우회하면 된다.
  • 15. 클래스 확장  드물게 Class를 확장하는 Trait이 있다.  해당 Trait을 확장하는 Class는 Trait의 Super Class가 Super Class가 된다.  Class를 확장하는 Trait을 상속받는 Trait/Class에 또다른 클래스를 상속 받을수 있다. 단, 이때는 서로 부모자식 관계로 이어져야 한다.
  • 16. Trait 셀프 타입  This:[type] => 로 시작  [type]을 상속한 클래스만 해당 Trait을 상속받을수 있음.  [type]대신 구조적 타입을 지정할 수 있음.
  • 17. Trait, JVM에서는 어떤일이…  Trait -> Java Interface로 변환된다.  구현이 있는 Trait은 해당 메서드를 Companion Class에서 Static으로 정의된다.  필드는 추상 getter/setter로 대체된다.