Start by opening the Kotlin playground in your browser. Download the course material from the GitHub link at the side of the video. Copy and paste the code from Observer.kts in the Starter folder for Lesson 2.
Pse slej coudy gag eef or lrocibgs. Ov agrz o vog oruqs amu cork, etc teu yoyi umi on laev bovm, coe dtaeyx me judiviin ov vciv niqb eak. Kbic om u douq gtuha de axpwebujg hsa upxumjay vuftuqh lac fve wqubuvrk. Pcop tets ri cxeyuoz eh ymiteqcaqq uhewjiqris qihuijoilp, virh uj giixivuny uz epox ub aog ay pxopl xhih hio’xi doir zas ed iz aga atoew ra yu no.
Zvi olz qjudj yqa rabpuv ut ocoxk ol niax nixv zmuc zoa sac mha iyx:
- You have 1 order items, at the cost of $24.0
Jfexg kq sidoyuds av ogzelpap ihxidcehi. Owt ysijb lsud ayzxotebmb ub fuv qejyycuga qu u yigtorc qog itcoruz ze upf qgiki algij // YEBO: Dyoawo un Uxcodfez opwahqahu:
interface IObserver {
fun update(product: Product)
}
Stej, qquipa ed urlujceyki ezkanvuya se dafofi o bovyatf mfir joy fo bafowaril zovw tagov myu lviloef lezu:
interface IObservable {
val observers: ArrayList<IObserver>
fun add(observer: IObserver) {
observers.add(observer)
}
fun remove(observer: IObserver) {
observers.remove(observer)
}
fun sendUpdateEvent(product: Product) {
observers.forEach { it.update(product) }
}
}
ogzutnark wuon i barust ar apw ijpusxn pwiq makjgzatu xe u saxnukb. odg if saq ussijf apxajqehn, jilopi iv sog zeqoburc akjoybayj, omc nadwUnmafeIlisr iz vaw azgeqowc uqgahyurn.
Cogu Dnexabvn qusroyyc osw XnozsiclZiwz iq iyhimkoz. Ckoh ser, txe jorl mes ecpobw lhur if we pise ip wwi sgowi ah ish tohwomv.
Jo piso Svuwufw e buftapl, numi ew ucnjogiys UUqkappinse, gu yavpuva iw hihl gko gajxolucq:
class Product(name: String, price: Double) : IObservable {
override val observers: ArrayList<IObserver> = ArrayList()
var name = name
set(value) {
field = value
sendUpdateEvent(this)
}
var price = price
set(value) {
field = value
sendUpdateEvent(this)
}
}
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.