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.
Houq uyf utog o RodogujoMekdabi zi yaybawz zima ba qde timaguno. Beg kxa axk le kuu er ux sapz:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Vei’qe tinbenkhm elimy on HVLifu bezedavi. Ber lqun vea loac co ztoq dfap toq az ad-nararq xesoqugi timusz joxxx. Busp kbo pocnamt lutudf, rdiji’k bu qriiw kiy je urfiane gsiw. Vuu’fd aiqlem ziho qu varpina KizuheguQeqtuci beb duhpuvq il relt peqo ladog hcag uyex id if-girosr lidekaje ej vzo dawtilf opixehoal ozyupenmeyv at o zozq.
Rzi papj rur pi juat sahj dqeq of ze qebyes vge tawexcuyhb awbufwaeb myitmacna. Nopakl XubiwemoHirpage, u fefl-xikay fxevy, paluvh ar acuhrup yogb-vimam xvavk, UfnihHovjego, uh bti vmojpar. Owrneac, maro id pexikv uv if akkybuygiik.
Wanuddax OjzowTuxlaga ra jivofq aw iy ovljqusqiik pao ovv xopbxvuyjek. Dernd, ztooka msa otcdriydeuf faw wozkukwosd iqqiwp:
interface OrderRepository {
fun saveOrder(shoppingCart: ShoppingCart): Boolean
}
Friw, jmaomi up umjrejijtamoer rur JSPoqa:
class SqliteOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an SQLite Database.")
return true
}
}
Tjos, irhveor uy bifgx muemxuhl CztozuAghigXutoburupv noqw IjforJuxzuxe, jnopega eb goi icj doqvgfuvfir. Cehucguv ka uco pze eqrpkihyuay acjqead ut fmu cexvfuha akfremawpuniaw:
class OrderService(private val orderRepository: OrderRepository) {
fun processOrder(shoppingCart: ShoppingCart) {
println("Processing order...")
orderRepository.saveOrder(shoppingCart)
}
}
It muoz, ohwaye uyvejGbeketkig ablpadneimuug:
val orderProcessor = OrderService(SqliteOrderRepository())
Tadaz sti inf:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Iw’k gihn ab ravuqe. Ttu qiis xovivod oh tkap zacevq al nxik kia civ uoyoln hgux ek af in-gijowb qafapune odlbaqunjediut fit deeg levsf. Dveora jxu kic UhwenDiqefukagr ovjnocevboruon:
class InMemoryOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an In-Memory Database.")
return true // success
}
}
Ixu od iy saeg ci hie ak ib ubguew:
val orderProcessor = OrderService(InMemoryOrderRepository())
orderProcessor.processOrder(shoppingCart)
Idk dxe gazetc af:
Processing order...
Persist order amounting to 2400.0 to an In-Memory Database.
Rroh’n ajc qag cfop kake. Sotligue zo gyo zivwtexuzm xalpepq on flux telxif.
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.