I've been playing around with Clean Architecture and VIPER.
Yesterday a friend asked me why not put the Interactor
logic on the server and just sync the processed data to the iOS client, instead of sending raw data and processing on the Interactor
. This would have a lot of benefits, as being able to change the logic at will, less code to replicate on multiple clients (iOS and Android, for example), etc.
For an example, say we have a list of Profile
s and a list of Post
s. Each post has an image and a profileID.
And let's say we wanted a screen showing a table view with all the posts' images and when the user taps on a post, we show the respective profile on a separate screen. In the profile, we would show the name and all the images posted by that profile.
If we leave the logic on the client, we'd be syncing data like this:
{
profiles: [
{
id: "...",
name: "..."
},
...
],
posts: [
{
profileID: "...",
imageURL: "..."
}
]
}
Then we'd have a ShowPostsInteractor
that would just return the data for all posts and a ShowProfileInteractor
, which would filter the posts' data to grab just the posts from that profile, then it would return some data to the view like:
{
name: "...",
imageURLs: ["...", ...]
}
The second alternative is to leave this logic on the server, in which case the synced data would be:
{
profiles: [
{
id: "...",
name: "...",
imageURLs: ["...", ...]
},
...
],
posts: [
{
profileID: "...",
imageURL: "..."
}
]
}
(note the addition of imageURLs
in profiles
)
And the ShowProfileInteractor
would just pass the profile data as it is to the view, since it wouldn't need to filter the posts anymore (this was done by the server).
Sure, the second approach duplicates some data, but since it's just strings, this wouldn't be very relevant.
I've seen the first approach done more often. So my question is, why would I not do the second approach (leave as much logic as possible on the server) and maybe removing all the interactors from the client, letting the controller access gateways directly, since there would be no processing of the data?