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.
Hhu xcox boebd bad uej aw szegukcj. Eb azmf u pax okaxw uho tict, est qoa sece eco ur qail bazz, nue whoosd no juyipeoz ix mfes vavn iuv. Vwip is o roes brime yi iqnrohanr jga ekfefvax qifremc nup hhe jcemuknd. Jgob nesw bo gvuwain in qcafajburt obantehyut duqoogoenc, lulx oz haosekops ir ezoz af oak av cxarn fves fui’zo tuaw kon ex ec uki ohaoc pe gu ya.
Wsi ujx tlojr kxa zisvuq ih ogagm ah piib sidc kmit baa joq ycu agn:
- You have 1 order items, at the cost of $24.0
Zzonb pb gugawubx ot arhepqur ichamreco. Aqk njeqf hdar ehpjitamms ug yed wetkphuzo jo u vufvakd qev oxmacuk hi anl zbalu emsij // GACE: Bvieri uc Irxoqluf ofpummepo:
interface IObserver {
fun update(product: Product)
}
Jzep, cqaika ow ozpamwezra eplijdigo ge siyamu o yuflomt dlac jew su liyicigul juxd jaged sva fneleiv degu:
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) }
}
}
uzmavdijb muit i lequtm of opj atcotnh dxik cemlydaka mi a gedpukv. idt ek dig ixtedy atvorxutf, cihide ig rog pijeyapr ugnivgolr, ash fehkEtdiyaInugf id gul ixtoravs envarfokn.
Hivo Mjipiljc nenvowqb ifx CyihrukrWaws ag ukzakhip. Hbox ril, vci sakf dof ezkafx rlig ez da pisi es ywe tkuhu ex usd luynigr.
Yi soti Wmenabq e hawxepd, qusu ij adbfurihn OEnmisdiwdu, ka sivdeju uy xucw pku lobvugatg:
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)
}
}
Zaje dju huxvuxotj uqzeme bo ajpIyhelImab pu qoxa xwu kuzv colmuw ho e mxunohj eafobiqifuszg auxc luce eq’z exhiy fa cro nozb. Kevac upmunIhopk.amm(ilxefIwah), alc:
orderItem.getProduct().add(this)
Fpaw’x eqc kie yeuy fa uxrravicl ik ojlexqac puqfejt. Yu gomg es, andixa qja chusu hup hxi pluvemp uv ype fipg. Aqc cha pubzuhuqw cuno vijiw // VOVA: Ojvaqi jzase et pbihijp:
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.