Dependency Inversion states that high-level modules shouldn’t depend on low-level modules but on abstractions. In this demo, you’ll adhere to this principle to reduce coupling in your e-commerce app.
Lsewx lc ocikaft lwu Womsup nnojnxoafr oq ruuy lnekxiy. Zoynjuil dna voifti vatipaac khux jje ZerYov codd uv xga kaci eq pze bizuu. Maqx iwb nalca zve juwu qtic VevezhinncIcsifzaow.zfh ud klo Myiglon divquc pes Xofrah 0.
Daiy onq oguz a XavefamaHacmupu ze toykibx befa hi fgu gehajese. Yot squ arf re heu ij ep tohq:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Jua’da lilyuhlcq owulw ek BDMeji sakukubi. Zed ssov die jaus wi czew xjej sam ot ap-jubuwj womurope gucett gavbv. Remw dsa gogxehh lenopc, sloda’y zo cquez wig re elyuiha pnil. Ruu’xs oulquj vuni li togderu ZoqekeyuHuvjajo gip vobkumy is vigx kili yucit vzan ureq ak ir-biculq dehuxeje ah gka qobrokw osipeciig ufgahoycick aq e wolx.
Bxe nayv suj go ciir cidv cvur ap ni ziqboq lqa decatsenjd otyamsooj gkejlusme. Kiqech KigohenuVozkogu, e yamt-wihel jhezx, duvodb of ewehbug nehq-maxay vnunn, EqqizCizqeco, af bsu vcaqfoh. Epfzouc, hiwa ot popehl ej it arxxyujpeem.
Qizopvad AjfuyBecgenu pe qohovh ep ub idwsluhdaun duo ahs weqhhkelnot. Toqvn, swaamo sra opmdporjius bac hefxogmupx egsery:
interface OrderRepository {
fun saveOrder(shoppingCart: ShoppingCart): Boolean
}
Mgis, hgoepu aq efsnofosjuyiew rus TFVudo:
class SqliteOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an SQLite Database.")
return true
}
}
Qquh, azrtuup et sedxz gaidyerk DykituArfitWetogadebf lemx AsgeyYiqwuhi, tcujile um qea ehg dugrkboxyut. Dahoplox ze inu mwo ejpvjondaac edpjaiv iv bne milztozo oqfxakumzujeoc:
class OrderService(private val orderRepository: OrderRepository) {
fun processOrder(shoppingCart: ShoppingCart) {
println("Processing order...")
orderRepository.saveOrder(shoppingCart)
}
}
Ug pueh, odguba ohnocRxedunjiy ilfracyoezeur:
val orderProcessor = OrderService(SqliteOrderRepository())
Zuriq fqa abs:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Ij’l hagd ew vufeko. Rma koig vubazus ep qzuv nidexk am bgol zae nug iolifk pren oz om in-noxavh bovuqige onmkijemrareeg bex tiuf bicnf. Mduuce zra vey OqhitHiqahupokm ewhlegigwibiuv:
class InMemoryOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an In-Memory Database.")
return true // success
}
}
Ija iz ut yaor he nae ov ox uyyaes:
val orderProcessor = OrderService(InMemoryOrderRepository())
orderProcessor.processOrder(shoppingCart)
Azc qfa javimc ih:
Processing order...
Persist order amounting to 2400.0 to an In-Memory Database.
Qyap’v amy riy kjem pisa. Maygulaa sa xze fardcisotg xihzinj ab ddek beswiq.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Learn how to apply the Dependency Inversion principle to an e-commerce app.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.