Hello,
Let’s start our article with some questions.
…
- How many models (Holding data only without any logic) at your main working project right now? 100 or 1000 or 10000 or even 100000?
- Is the same quantity of models at other platforms? (If you are iOS Developer, is it the same at Back-End and Android and Front-End?)
- Are you have many redundant/duplicated models at your project?
So, let’s make it clear…
First, the quantity of models is not important if everything has usage and it is clear.
Our article is about “Unify Data Layer at Software Projects”
And, of course you are suffering from having a lot of models have same variables with just small changes and you make them to confirm APIs response at different routes.
For example:-
You have endpoint to get List of users and response is list of user as following:
public struct User: Codable {
private let id: Int?
private let name: String?
private let phone: String?
private let email: String?
}
And, you have another endpoint to get single user and response is user as following
public struct User: Codable {
private let id: Int?
private let name: String?
private let phone: String?
private let email: String?
private let country: Country?
private let currency: Currency?
private let wallet: Wallet?
}
What do you think , you should create the response of two endpoints as one model or create two models to each response?