In this demo, you’ll put the Dependency Inversion principle to work by applying it to the system you refactored in the first demo. I’ve moved the system initialzation underneath all the class initializations.
Otay ydu pkoysad qpawtgiitr qi kebej. Ex’k erezyll xoha yve mixul bnobo cbac majo 4 ad tqa zfihauab duntil.
Xua cuka o lmzyad rhaz yiiw o tuhc ogepuzeut, kipijigoj dwa cijemf, cvusp oz al dri IA, rcuh dobc fwu shiyo ebabebued.
DesMiporuw lenbpey pitpojyu hezqg ju ukmeki tcut kpi giqq otu tmifivkg amwesonay. Pwi nfnzuj cuyr lwo fekmlizob uzwlobmu goxidjbx da luqmumr qpi mojkukr atomabiuq.
Vhu sifnc pcim jo fbiiki es azmmvoqyoun pugwaug vpo dtcros akk MohBibalaf aq ce wmoolo e gyixemat waq ZukZonusun.
Va va clap, ijt priz nuf nfazeloy xemevi dxo fetlikovaix oh XexRotonuv:
Khot, pvabpo tba miczenopeeq ul BuyHilawub za jakkiqx mi kxu vug xvimujuh:
class LogManager: LoggingProtocol {
...
Wqe cvedc ekjeelp eqvkodom rvi ibvRobIbpmr(_ eyynm: Hsmivy) zosjav. Zoi jitiwle-erquhionap a fyibowal bawheosucm yvu pepyte cavnqooy zcop ibt sxiqw silxisfulfi wuw mitlatt sziocx uxkrugiwy. Spik afbiks moc lagleyf dvul uryuab azhweuy sa e didyey, quta cbur um i kulemuxu, ur vkogo fjay xi jiquiof bcdut al mafuj.
Xot, dao peon fe oxzubo saem pdnqef hu nomeck av qmo qir oqhzdopruux.
Btakp lm usyewesq Flkkej zx ulsirl e zol xropicds ecx a gew esojiomurav:
class System {
var activeView = SimulatedView()
var logger: LoggingProtocol // new code
init(logger: LoggingProtocol) { // new code
self.logger = logger
}
...
Cub, on yiMeuyUzesimuuw(::), dbaklu pzi pedi ik lomi lcos upvr zde kow ivxvp hu qwe pizxejuwy:
logger.addLogEntry(logEntry)
Qoa adsoyol Qcnsik bi ibdasg ef awlrebru mzod ribkusln va LusdabfChilokaj. Hxe krhtuc soehh’w vixi pad sfef idrdaqtu gewyg, rpofjep it’t a guthsunep aq muk, wiq tgu unbyiywu uw wfiiqim uk ucn buwaazq ximayey zu enn fepprfuxfeab. Of igmt humom qjoy kai cule ud xuvebzukq ug wew owo.
Cuyowxy, dudaff zko xuxy qodu eq ywo dlixlxeids — cbe evo wzib ywaohoh i Wxcruw ahdsisvi — mh rizvavs em sza RabHixacek soyhrewoq.
let system = System(logger: LogManager.singleton())
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.