Design Patterns Flashcards

1
Q

How would you explain delegates to a new Swift developer?

A

Delegation allows you to have one object act in place of another, for example your view controller might act as the data source for a table. The delegate pattern is huge in iOS, so try to pick a small, specific example such as UITableViewDelegate from UIKit – something you can dissect from memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can you explain MVC, and how it’s used on Apple’s platforms?

A

MVC is an approach that advocates separating data (model) from presentation (view), with the two parts being managed by separate logic (a controller). In theory this separation should be as clear as possible, but for bonus points you should talk about how view controllers sometimes get bloated as code gets merged together into one big blob.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you explain MVVM, and how it might be used on Apple’s platforms?

A

Start with the simple definition of Model (your data), View (your layout), and View Model (a way to store the state of your application independently from your UI), but make sure you give some time over to the slightly more nebulous parts – where does networking code go, for example? This is also a good place to bring up the importance of bindings to avoid lots of boilerplate, and that probably leads to SwiftUI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you explain dependency injection to a junior developer?

A

Dependency injection is the practice of creating an object and tell it what data it should work with, rather than letting that object query its environment to find that data for itself. Although this goes against the OOP principle of encapsulation, it’s worth talking about the advantages – it allows for mocking data when testing, for example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you explain protocol-oriented programming to a new Swift developer?

A

POP is a Swift buzzword, but don’t get carried away with the hype here: focus on why it’s different from OOP, and what benefits you think it has. You might want talk about horizontal vs vertical architectures here – larger codebases are likely to have sizable class hierarchies – but you could also talk about how POP is able to work with structs and enums as well as classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What experience do you have of functional programming?

A

The best answer of course is to provide detailed explanations of what you’ve used and where, but as you go make sure and talk about what functional programming means – functions must be first-class types, you place an emphasis on pure functions, and so on.

If you’re not sure where to start, the easiest answer is to list some small specifics: if you’ve used map(), compactMap(), flatMap(), reduce(), filter() and so on, that’s a good place to begin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you explain KVO, and how it’s used on Apple’s platforms?

A

KVO used to be helpful in UIKit to watch for changes on values that don’t have useful delegates – you can literally say “tell me when this value changes.” Try to give at least one specific example, such as watching the page load progress on a WKWebView. If you’re exclusively using SwiftUI chances are you’ll struggle here.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can you give some examples of where singletons might be a good idea?

A

It’s very unlikely you’ll join a company where singletons are used extensively, so feel free to say that broadly speaking singletons aren’t great. Once you’ve given up that proviso, perhaps mention that Apple uses them extensively – thinks like UIApplication, for example, are designed to exist only once. Finally, try to give a fresh example of your own, such as creating an app-wide logger.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly