- 
                            
                            Kotlin Delegate PatternKotlin 2023. 6. 3. 19:07반응형https://github.com/DNights/KotlinDelegateSample GitHub - DNights/KotlinDelegateSample Contribute to DNights/KotlinDelegateSample development by creating an account on GitHub. github.com Kotlin Delegate Pattern 이란? Kotlin Delegate Pattern은 클래스에서 특정 기능을 제공하지 않더라도 해당 기능을 제공하는 다른 클래스에 위임하는 방법입니다. 이를 통해 클래스는 더 간결하고 유지 관리가 쉬워집니다. 
 Delegate Pattern을 사용하려면 먼저 Delegate 클래스를 정의해야 합니다. 이 클래스는 클래스가 제공해야 하는 기능을 구현해야 합니다. 그런 다음 클래스에서 Delegate 클래스의 인스턴스를 생성하고 해당 인스턴스를 클래스의 속성에 할당해야 합니다. 클래스의 속성에 값을 할당할 때 Delegate 클래스는 해당 값을 처리하고 클래스에 필요한 기능을 제공합니다.
 Delegate Pattern은 클래스를 더 간결하고 유지 관리가 쉬운 방법으로 특정 기능을 제공하는 데 유용합니다. 또한 클래스가 제공하지 않는 기능을 제공하는 데에도 유용합니다.Sample code interface Base { fun print() } class BaseImpl(val x: Int) : Base { override fun print() { print(x) } } class Derived(b: Base) : Base by b fun main() { val b = BaseImpl(10) Derived(b).print() }결과 값 10 [참고 자료] https://kotlinlang.org/docs/delegation.html Delegation | Kotlin kotlinlang.org https://en.wikipedia.org/wiki/Delegation_pattern Delegation pattern - Wikipedia From Wikipedia, the free encyclopedia In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance. In delegation, an object handles a request by delegatin en.wikipedia.org [Delegate Pattern] 1. Delegate Pattern이란? 목표 Delegate Pattern에 대해 이해한다. Delegate Pattern이란 Delegate란 한국말로 위임이라는 뜻이다. 우리가 계약서 등을 작성할 때 대리인에게 결정 권한을 위임한다고 하면, 대리인은 우리의 결정 권 kotlinworld.com https://medium.com/genetec-tech/the-power-of-kotlin-delegation-e6d45fe85e24 The Power of Kotlin Delegation A comprehensive guide to Kotlin Delegation medium.com 반응형'Kotlin' 카테고리의 다른 글first-class, High-order function and inline funtion (0) 2023.05.02 kotlinOptions useIR 의 의미는? (0) 2021.12.17 Kotlin Spread Operator (코틀린 스프레드 연산자) (0) 2020.12.16 앱의 미래 : 선언적 UI 와 Kotlin MultiPlatform (Daniele Baroncelli) (0) 2020.12.15 Kotlin Cheat Sheet and Quick Reference (0) 2020.07.23 Kotlin SMA (single abstract method) Conversions (0) 2020.07.22 Introduction to Kotlin coroutines (0) 2019.10.10 lateinit / lazy 의 차이점 (0) 2019.10.04