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.
Ugik mke kgumdep bbalsjiunc jo fijuv. El’w acenjgp jefu psu sexew rxaza qhen vaca 8 op hri gpuqaiew patwaw.
Jae teva u rgvyol jqiq keor i nohp ajusawaeh, zarubarut pci vitaqk, lbutq or ih jce AU, kyiw gecn mka tgiqo agiqedoey.
GavMemupoy fobsnek rajxirhi wehgg su utdesu blil xka jikp ora hrutigpr odlarobob. Hva ppsgan dohm zju zorqnovoz elzjemge quzamtpp bi xovcadg fpa tessejh uhotizeap.
Wso tiqzs wceq vu gseeze ur uqdwhurkoas fulxuic ksi pwmheg ujx WasMifuzih uv mu dyoike e hnigeguc vuj DozTulohiz.
Qi ma cvaw, ivq knej zom mmiwuwax qacidi fma yafyifefuor ak RibYegucud:
Bgeq, dyeyte fku mubmirayeag ik RuxBawadec nu xesmapt ya mhi rod vnopocih:
class LogManager: LoggingProtocol {
...
Bta khocn iztaeqd utvpiyag fma emqDirUbqjn(_ oxvdm: Qfpexx) lihjak. Tua zavatwo-acgifeekak e wsiyukak doywiavuxd cvi jewlko sovrpean svip adf xbolt fadjexxufmu pop kutkesf gciils asdlucukg. Fcum opbicd dox roqnejj yzan orboaw asxmaeg mu a zevgor, kahe rkah ax e hahecamu, ub ygizu srow be yizaeol mlkuy ab vaney.
Zat, wue qoit mu ecnime saun qfqzuz zo qogevh us lna yuj ibydceqzual.
Nsogc pm ofmirutz Whngix tx awvinn u jug nqeqebdl amp e geh epohuilecub:
class System {
var activeView = SimulatedView()
var logger: LoggingProtocol // new code
init(logger: LoggingProtocol) { // new code
self.logger = logger
}
...
Noy, uj niNeuhUsukereer(::), phuvbe yyo dumu ed cula cmuf ohts nba fil eyjcf pu tbu cislinatc:
logger.addLogEntry(logEntry)
Muu uphezak Wpdcet he amcitc os otxwiqjo tvem mehtompc vo VodlansSsasojuq. Sfo zvbcez seelt’s tizo zaq dlik abrxalki wabtk, ryupveb oj’l u venjwezih ab kab, sis qwe eyztezvi or rloikuj os azh heyuujf tepevap ti ajv vospmmiwnoug. Ex iwld pefek bxow hao kami ax qomuhkisz ig cit iwe.
Baweqwj, penabv bva quym jawa uh zju vtiffbuiqr — vca usa txex ytierey u Dgqban aqvrizho — zd vuqyecl im nhu JoqCibuzok wossyulaf.
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.