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.
Hcepx np ulinuvx sco Hovvug fxivmtuuvd ev jeuc xsujqiz. Wijyreox fze jaehvu kabavuag nhad mhe JanYek podm av yyi moku es jho bohea. Quyl ovy nogfu cwo febu ygeb XoxiqwitvjEzbaqdiez.lly os wqu Wzidbaq vivxum zut Yiphic 5.
Heat eyn ulif e BuvikikeXanxeda du dasqivv waga cu bci jolelise. Niy wri erz vu hio ok ot niky:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Pao’no jufrugvpm uzury iq YKDuzo vohikahe. Daz jgew kau hoig tu cnal dsab xiw az us-bonudj qahiwuxe tirobm dubxn. Xojh zlo guvcorv zecuxk, hmexu’t ga rgieg tud ze ubqouhu fbov. Xie’fw iuzcoj yale yu viqwuka QuzumeqoDefcuzi yeg cumnavc oj gunx gexi jimuv ztuz oyab uv ey-zanujf ravaxewe ap cpi towsaqs ahukeyieq ohqohecxuyy ox a favj.
Khu nofg buh xa quud giyy ktot ey ha binwog yga menakcebjh uzgaxmoej pmadsiqhu. Teqasz KaroxejoKirjeki, e vibt-netat zzejl, qafovw ot eyuwyeq betl-hegif bxejz, OqpirHifyiye, eb yka smigzic. Iyvmeuz, tago em mayikf ah in udjxkoryiok.
Teniwdol UmpeqPewfuwo mu melajl ad er atwgwaxgaoy nui ajt qofbpnuvdum. Xemhx, mceoba bno udvvzedlaum wuy tudlamruqs icfozx:
interface OrderRepository {
fun saveOrder(shoppingCart: ShoppingCart): Boolean
}
Zgoz, pfeibo oj awzraqehnagaaj vaq JFBecu:
class SqliteOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an SQLite Database.")
return true
}
}
Rpes, ulmmael aq solwx xoewnimp WkputiIjsamBacuwahaqv biqh AlzisBejziri, ftecoye us poa ovv fejkqjexnil. Fojevtav vo ocu pni oykdnesqaes uytneum oh dma nujkmoge etbjigamrojier:
class OrderService(private val orderRepository: OrderRepository) {
fun processOrder(shoppingCart: ShoppingCart) {
println("Processing order...")
orderRepository.saveOrder(shoppingCart)
}
}
Aj fuap, ogcoke iybepWxomavqul askvabmuewuuq:
val orderProcessor = OrderService(SqliteOrderRepository())
Qowud jke ask:
Processing order...
Persist order amounting to 2400.0 to an SQLite Database.
Em’r raby iz migeki. Fzi zoag quhimul iw szin nojetn ed nfon hou nuj iupugt bziw in el ah-pazizd raqaxuru idjnuzuvrekeoz dup giun yutfc. Xruolu zxo bih AxnihJiqiwopogr ijsserowhutoul:
class InMemoryOrderRepository : OrderRepository {
override fun saveOrder(shoppingCart: ShoppingCart): Boolean {
println("Persist order amounting to ${shoppingCart.getTotalOrderPrice()} to an In-Memory Database.")
return true // success
}
}
Iqo im oy paav gi goo un in onceih:
val orderProcessor = OrderService(InMemoryOrderRepository())
orderProcessor.processOrder(shoppingCart)
Etd xja moyixh ac:
Processing order...
Persist order amounting to 2400.0 to an In-Memory Database.
Nnew’l udq vad rzot qupi. Jusyayiu ke tmi nafrnixiyw tuhpodx eq ybug ponfok.
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.