DEV Community 👩‍💻👨‍💻

Fernando Martín Ortiz
Fernando Martín Ortiz

Posted on

What’s the model?

I teach iOS development as a side job. I work 9-5 (well, actually, it’s a bit earlier than that, since I’m working for an English company at this moment). After I finish working, three times a week, I teach iOS development to different people, for two hours. They are starting their careers, and they are developing their intuition about software engineering.

That’s really interesting from the point of view of somebody who has been in the industry for some years now. It’s good to remember how you started and what errors did you make at the beginning.

Today, I’m going to talk to you about an error I see over and over again, and recently, I think I reached a way of making people think about it, and reason about it.

Imagine you are developing an app for ordering food from restaurants:

  • You have a listwith different dishes and options.
  • You can add more units of any of the options you have in the list.
  • Each item in the list has the number of items of that type you’ve already added, it will let you add or sub any number of items at any moment.
  • Whenever you add food, there is a shopping cart or something like that at the bottom of the screen where you can see immediately updated the price of the food you’re buying.

Fairly simple, straightforward problem.

So, here is the thing. There are many ways on how to develop something like that. Imagine you’re using UIKit for now, and not SwiftUI. You would have tableView or collectionView cells for the items in the list, and you would sum to the amount that you have in the bottom.

This is how people tend to design these kind of apps when they start:

  • They detect the event to add more items of a certain type.
  • They check the label in the cell to know how many items of that type they have already added.
  • They add one to that number.
  • They update the label in the cell.

And they have similar solutions for the different parts of the UI in this and similar problems. They rely on the UI as the source of truth.

So I started to ask them: What is the model?. I start any exercise with them in the same way. Regardless of how simple of complex a screen is, I start asking them: What is the model in this UI?

The other thing that’s related to this I use to tell them from the very beginning is: We are UI developers. As UI developers, our goal isn’t only to deliver delightful UIs with animations and beatiful graphics. Our goal is to ensure consistency between the model and the UI. The part about the UI is usually easily understandable. The part about the model is very hard to understand when you’re starting.

Our goal is to ensure consistency between the model and the UI. You have a UI, what is the model?

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.