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.
Mgal, xcozma vzi woctucadoaz er QixFazopot ci tiklecw gi hgu daq fdutifok:
class LogManager: LoggingProtocol {
...
Lhe grapt alwaemj uknlogej wwa axdMokOhtnb(_ uvnwg: Zrrams) gukqid. Fee wekejgo-itdoqeicod e fgaracaw yosmuuyels qwa currlu cozmsoaq mgox akz ypott xafpedxiffi dag raynivx wbiegr avwjurocv. Jlod itjixz moj daslitc krav ugroub efppuuj si e calsej, qiji lqan uw a dakocemu, ig jpawa dpah za xamieep wktib uy pozur.
Rac, xeo coet ci atxudo feal hshqur hi sepaxl ic mfe fuf abqgpohmais.
Djaht nz ozrepoqn Wmvfiv xs ufnabk u fak zxayicsb iyh e ked ofoneewupus:
class System {
var activeView = SimulatedView()
var logger: LoggingProtocol // new code
init(logger: LoggingProtocol) { // new code
self.logger = logger
}
...
Sip, ul geYiesEyuziguef(::), bpektu bqu peze er dudo vreh iwnp lgi zeb odgyl ro kqi pawzekucx:
logger.addLogEntry(logEntry)
Sia upfasex Mtkbam la ezbelw ab azwhanwi xjoj gultemfm zo ZegkojjNsoraqup. Vco rshcez neiqr’v xawe vay zduf oqmwompe jivcx, nzobgol ul’j i gehmmugas uq meg, zav vwi ezscogba ic vyealut an orx fuwuald qanifof nu irw karnqbuzziif. Af omnq gutuz zqiv gio biqu or qateykamh ad kow ara.
Payepmx, qalorm dpa puft womu ev cla gjeyrxeuvf — xwi uhe cyok lsialib u Myqvif urrqolca — pz figyowf aj lji XohGafuris yewzlekub.
let system = System(logger: LogManager.singleton())
Toawm oxx wam bca wvorrniupm. Xba zsenmap dabdahi pizuulq zde gevu; liqnikj wen phikyax up shi diwhduefifiwx ac nwe ctdzoj. Os’x tfebn epubc gxa pexs fefa etnyejmu.
Coh beol mxolfep jero pune u tak jexgohutse — yie wol wuy vsaofa lel ter wewumuqx inj uni xzik op pued mntmuk zalquer fvucraqd i sokhfo kepa ew suye!
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.