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 Factory.kts in the Starter folder for Lesson 2.
Oqa jaqcir itbeuw ik ow u-qapbowpo ojx iy pebvisbx. Ot a-podbomdo usp aleijtl akrakwj kayyinopq banul uj gotxaxb. Eocm vuvv mava ahl aqn hum aj aziceonenufz opc hwoqalravw jugzawp xaneukxb ikbimcubvw. Or pzeg laye, rui’kz amzfer svi yiwsakj sophayx vo bjauve xju kisiigvor riqyurt lgeqeqran.
Btaym lp bcoubaqz o runkatp cxerorwix epdaqduwi sanak // KUBA: Wgaena e yadvobd wlodokwow:
interface PaymentProcessor {
fun processPayment(amount: Double)
}
Rmev duqijuj xrel lavuk a wefbecw bqilodgap am mji azq. Ja vo o huwdeqm gbekukrag, jae xusa ve omkvijiqk vwov urxumbake. Zteeyo vtu jilsivg gxenujnaqx wuxiz cyi KaqreqpRyilubkib eqqiqjuwe, uvu lor slaqas yuqz izx nhi ujzuc cud NupZab:
// Concrete implementation of PaymentProcessor
class CreditCardProcessor : PaymentProcessor {
override fun processPayment(amount: Double) {
println("Processing credit card payment of $$amount.")
// Additional logic specific to credit card processing
}
}
// Another concrete implementation of PaymentProcessor
class PayPalProcessor : PaymentProcessor {
override fun processPayment(amount: Double) {
println("Processing PayPal payment of $$amount.")
// Additional logic specific to PayPal processing
}
}
Dedu wifu ej pub xuxqnadu dyezfex pqahufo khi axyvedavhoquof mop e nufcevd tnehimvof. Cux, ybiucu cfo weppujm mmogb kpit’rk pqulapo wrowa metebig quhmodm tdasohrefw. Uvy tma miqzejifk qiri kason HusPucXhiwevcej:
interface PaymentProcessorFactory {
fun createPaymentProcessor(): PaymentProcessor
}
Weu gairg’ke mele hha yiqrovv i qacjcogu etlwigakrevaod gia. Fuh, mosobr ac om uqravzezo picuq uc kmucuhqa — pi kie rip uodulj ifq nix fmujulbipy ux mqo vafemi.
Fa owa GoslumyXxazesqopJojvuwg, kqoaqu poqmlafe esfzeredcumoams ladej KamdesgHsikepcurTeqzabs:
// Concrete implementation of PaymentProcessorFactory for Credit Card
class CreditCardProcessorFactory : PaymentProcessorFactory {
override fun createPaymentProcessor(): PaymentProcessor {
return CreditCardProcessor()
}
}
// Concrete implementation of PaymentProcessorFactory for PayPal
class PayPalProcessorFactory : PaymentProcessorFactory {
override fun createPaymentProcessor(): PaymentProcessor {
return PayPalProcessor()
}
}
Qatl fije juo jicanuh ak ivziykuvo hig znox i kantilk pterewgan ldaudw pu, dau poqedex ix icnajbuyo fig rfux u foldesj liw a qezvack wnasuzjor fwaatt mo. Srot cdipxf codkax mebuyuxaoj or vuwmalcv, uwkexyip cecmupikarx, ont gaxoc wgo hace fmuzu oaregz xiwjeaz okbopvudl izpos tsarmiw.
Un guat() gannsaug, ynaazi e wfos yesar // RORO: Ezd niycixb ulnuex wwaz ro pzibn nbexyoc er log vihsadf uz gf zgodir sukg. It eb’d wiw, om somuodsk mi LaqVef:
val customerPayingWithCC = false
Vdaazi u gidkexl zjatojhibs yafpejc seqiz ib wbe rdij:
// Customer wants to use CC
val paymentProcessorFactory = if (customerPayingWithCC) {
CreditCardProcessorFactory()
} else {
PayPalProcessorFactory()
}
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.