I'm using MVVM + Clean Architecture in my app. And I sometimes don't have any idea if my namings are good enough for each Interface Adapters, Use Cases / Interactors, Entities. For View Models, it's pretty simple. I can just use xxxViewModel as the name. But what about those before? FYI this is my usual namings:
- Interface Adapters: I use xxxService for the interface / protocol and for the implementation I use xxxAdapter. And for the prefix, I usually use the bounded context. For example I use AuthenticationApiService / Adapter for the Authentication context API calls, AuthorizationApiService / Adapter for the Authorization context API calls, AppointmentApiService / Adapter for Appointment context API calls, StripeService / Adapter for the Stripe framework, GoogePlacesService / Adapter for Google Places, etc.
- Interactors / Use Cases: Since I injected the function instead of the class, I just use the intention of what I want to do as the class name. Eg:
class SignIn {
let authenticationApi: AuthenticationApiService
init(authenticationApi: AuthenticationApiService) {
self.authenticationApi
}
// This func will be injected to the view model as the dependency instead of the whole class
func dataTask(username: String, password: String) -> Observable<UserEntity> {
authenticationApi.signIn(username: String, password: String)
.map { decodeToUser(response: $0) }
}
}
But some of the interactors are grouped together into a big class if there are too many that should belong to a single classification. Like Appointment context interactors (basically a class with the whole CRUD operations in it). For this kind of interactors, I am usually unsure how to name them. For the Appointment one, for example, I just name it AppoinmentHandlerProtocol and AppointmentHandler classes for the protocol and implementation.
- Entities: I just use the naming of xxxEntity like UserEntity, AppointmentEntity, CreditCardEntity, etc. Kind of straight forward although I don't know if this is correct or not. Heck, I don't even know whether they are truly entities or just some POJOs or DTOs. Because I classified all of them as Entities (as in Clean Architecture's definition of entity). Although it's not really a Plain Old Object because I at least have to implement Equatable to make the testings easier.
- ViewModels: For these classes, I just use the naming like xxxViewModel based on the corresponding Views.
I know that this question is not really an objective one and it's a matter of preference. But I only want to get lots of feedbacks for this.
Thanks in advance.
EDIT:
The example of the code can be seen here: https://pastebin.com/brA83jNy