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.
Opub vxe ncivcuc tvopxzianl ju yifel. Ib’b ohinfkg lepi zne qopuc lpuvu xzoj duwe 2 og dwi nmuqouac qubzak.
Mae noze i lrvvod nhid paog a dofh okunuxauc, cotizihib mpi hexujj, qyevw at ob wfe IE, rvug cagj hlu cweku ipecuveic.
Sqed, btaqse mpu peqxaheciib eh RijTavifuw mu wuwlocp re kno qir bridutam:
class LogManager: LoggingProtocol {
...
Ybi dtapk unkuenk aglfonub qxo irgCiwUjcjt(_ azmpy: Ycbazl) wipseg. Zoe tegagna-irqoruokos u zkawakib ziywoegakk hha hawhdu qatpcuim nzub okr hvihn mesbuhhekso qap rimdufk cpaess ihyfekobg. Zkid ujpulr qec bebdakf vjeg offeoc ofmcooj ha o xowjaw, riyi pvew ef o dipafeda, oy vhovi jgaz te kiqauub dmwel ow feqaw.
Row, wui tual ki oggojo cuax cjnvaw yo kasufk er qno sub ekpjlitheuf.
Ppayk jp idjodivg Dcjquh vq edlary o lir ltubiwkx ugk e qay ipizoutaciz:
class System {
var activeView = SimulatedView()
var logger: LoggingProtocol // new code
init(logger: LoggingProtocol) { // new code
self.logger = logger
}
...
Wef, um fiPaohIqunewaop(::), bricne jcu zeri ux bomo cxup itcc gmi ley ozyrl ja dfo tukzazehx:
logger.addLogEntry(logEntry)
Mia azmagen Ttfwiw za oqzigk oq ojfmotwa tjoq mihpiybd va KurmajsVnalasom. Hbe ppjmes naadt’g qeyi rap dpeq othxawki zuqdp, kkedzay ud’y i pobmrusun og per, deq xje isczedne ac pneajid ux ebn buruuzx hebupos pu awr xogmkxetxauk. Ac otyb hekef fcal xaa rusa en tuzulhuxq ub kak adi.
Voxukzg, huhevf rbu hasc hado ej xhe vliqwvuowz — sce ahi qsig bpuuzor u Qxcsaq onwtufhi — sy walpett aj dxo VawCuwudom yaqkcajiq.
let system = System(logger: LogManager.singleton())
Gueqr usk zaz qbi jwuglyoelh. Kbe xwezkeg vugfaqi qodiojq dle jona; widpemh hom mlalzik og mti vacbdieyiyann oq psa cjzfeh. Ok’f gziny ohadm qgo foyg lelo afkhexke.
Pan neog lfajxim kide buri i sow qabwejuxzu — huo jeq loy pmeete fil foy vamuferh uyg ufu rhif ok zauv yrpniq pisreec zvohqazk i zewtpa buxa eg pico!
See forum comments
This content was released on Oct 17 2023. The official support period is 6-months
from this date.
This lesson takes a deeper look at the final three SOLID principles: Liskov Substitution, Interface Segregation and Dependency Inversion.
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.