ؘ য ݻ о णפ. ਤ ܳ ё ೱ য۽ ҳഅೞӝਤೠ ݫழפ્ੑפ. Using Prototypical Objects to Implement Shared Behavior in Object Oriented Systems by Henry Lieberman Pluu Dev.
T> { private var value = initialValue protected open fun beforeChange( property: KProperty<*>, oldValue: T, newValue: T): Boolean = true protected open fun afterChange( property: KProperty<*>, oldValue: T, newValue: T): Unit {} ... } ObservableProperty
blabla2() } class AImpl : A { override fun blabla() { println("Hello delegation!") } override fun blabla2() { println("blabla2 delegation!") } } class B(a: A) : A by a ਃೠ ࠗ࠙݅ class C(private val a: A) : A by a { override fun blabla() { println("Override method!") } } class D : A by AImpl()
lazy { getString(resId) } fun Activity.bindColor(@ColorRes resId: Int): Lazy<Int> = lazy { ContextCompat.getColor(this, resId) } fun <T : Parcelable> Activity.extra(key: String): Lazy<T> = lazy { intent.extras?.getParcelable<T>(key)!! } fun Activity.extraString(key: String): Lazy<String> = lazy { intent.getStringExtra(key) } class TestActivity : Activity() { private val title by bindString(R.string.title) private val accentColor by bindColor(R.color.color_accent) private val param by extra<Param>(KEY_PARAM) private val keyword by extraString(KEY_KEYWORD) }
private val name: String, private val defaultValue: Int = 0 ) : ReadWriteProperty<Any, Int> { override fun getValue(thisRef: Any, property: KProperty<*>): Int { return preferences.getInt(name, defaultValue) } override fun setValue(thisRef: Any, property: KProperty<*>, value: Int) { preferences.edit().putInt(name, value).apply() } } class Test(private val pref: SharedPreferences) { val count: Int by IntPreference(pref, "count", 0) }
QuizType1(b, 30).printX() QuizType2(b, 30).printX() } interface Quiz1Base { val x: Int fun printX() { println(x) } } class BaseImpl( override val x: Int ) : Quiz1Base class QuizType1( b: Quiz1Base, override val x: Int ) : Quiz1Base by b class QuizType2( b: Quiz1Base, override val x: Int ) : Quiz1Base ? ? ?
{ println(x) } } class BaseImpl( override val x: Int ) : Quiz1Base class QuizType1( b: Quiz1Base, override val x: Int ) : Quiz1Base by b class QuizType2( b: Quiz1Base, override val x: Int ) : Quiz1Base fun mainTest() { val b = BaseImpl(100) b.printX() QuizType1(b, 30).printX() QuizType2(b, 30).printX() } 100 100 30