Friday, August 19, 2022
HomeiOS Developmentios - Is it appropriate to separate the obligations between the Repository...

ios – Is it appropriate to separate the obligations between the Repository and Knowledge Supply courses?


I’ve applied the info layer of my app following the repository sample. The principle purpose of it was to have the ability to work with totally different APIs for a similar goal. Within the present structure the duty of the Repository class is to map each the Area Mannequin to DTO and the DTO to Area Mannequin. The information supply class is the place I put together the community requests (with parameters or the area mannequin from the repository class).

The present architectural movement in the meanwhile is:

  1. Manufacturing facility object (which initializes the Use Case with the repository and the info supply)
  2. Use Case object (with the repository dependency injected)
  3. Repository object (with the mappers and the info supply dependencies injected)
  4. Knowledge supply object (which holds the response sort object)

I’ve been researching the repository sample for some time now and I are inclined to see that everybody places all this logic contained in the Repository class as a substitute of splitting the obligations.

Right here is an instance of the code contained in the Repository’s class:

struct GetCategoriesRepository: GetCategoriesRepositoryProtocol {
    var mappperDTO: MapperDTO
    var mapperDM: MapperDM
    var dataSource: DataSource

    init(dataSource: DataSource,
         mapperDTO: MapperDTO,
         mapperDM: MapperDM
    ) {
        self.dataSource = dataSource
        self.mapperDTO = mapperDTO
        self.mapperDM = mapperDM

    func execute(
        _ domainModel: DomainModel,
        _ completion: @escaping ((ModelCategories?, Error?) -> Void)
    ) {
        let dto = domainModel)

        dataSource.execute(dto) { (classes, error) in
            if let classes = classes {
                completion( as? ModelCategories, error)
            } else {
                completion(nil, error)

On this approach, the repository implementation is identical for various knowledge sources as a result of the logic is inside the particular Knowledge Supply courses. I am nervous about having the logic break up in several courses as a result of this interprets in increased effort to develop new use circumstances. Additionally, I haven’t got a protocol to which each repository conforms to. I usually have one repository to be used case, and in addition a protocol definition.

Is that this the right approach of implementing the repository sample?



Most Popular

Recent Comments