Better Programming

Advice for programmers.

Follow publication

Member-only story

Seven (or So) Flavors of Dependency Injection in Swift

Nikita Lazarev-Zubov
Better Programming
Published in
7 min readOct 9, 2021
Photo by Matthew Henry on Unsplash

One of the programmer newbies that I’ve met said to me once (brooding deeply): I thought that the bigger the class, the better… You know, then it can do more!

Time goes by, newbies become experienced, and big mighty classes lose their attraction. Programmers start realizing that they need to return to the same code over and over again, and in order to keep code maintenance effective, the code should be testable and easy to understand. This is where dependency injection comes in handy.

Note: This post is not considered as advanced and is more suitable for upper junior-intermediate level programmers. However, it’s always useful to brush up on basics even if you’re a seasoned engineer. Especially since I like to go a little bit further the main focus in my blog posts and cover useful companion techniques too.

Motivation

The main principle of the technique is to recognize an extra responsibility of a class that can be extracted out and mounted on another class (separation of concerns).

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Nikita Lazarev-Zubov
Nikita Lazarev-Zubov

Written by Nikita Lazarev-Zubov

Swift and general programming topics, Agile software development, soft skills

Write a response