Riccardo Cipolleschi
1 min readNov 27, 2021

--

Hi Jono, nice to meet you and thanks for the question.

I think it is a matter of preference, here. Your approach is completely valid. The only caveat is that you are exposing the ViewModel type and its initializer. Practically, the ViewModel must be `public`, its `init` must be public and all the internal types used by it.

In a modularized environment, this means increasing the API surface and it increases the risk of breaking change. You can read more about best practices when writing modules here: https://betterprogramming.pub/6-principles-to-write-better-modules-for-your-ios-applications-3257c26e5df2

To be more concrete, imagine that you decide to create another ViewModel for your view, with slightly different parameters which can be computed from the original ones. You will have also to change the composition root, because the VM.init signature has changed. With the approach I proposed, that will remain an implementation detail, internal to the View module. Does this make sense?

I'll be very happy to discuss the matter further if you have any doubt.

Have a nice day,

Riccardo

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Riccardo Cipolleschi
Riccardo Cipolleschi

Written by Riccardo Cipolleschi

Hey there, I’m Riccardo. Software engineer at Meta. I have a passion for iOS and I love to share my knowledge with others.

Responses (2)

Write a response