Wednesday, May 4, 2022
HomeiOS DevelopmentIs it appropriate to separate the obligations between the Repository and Knowledge...

Is it appropriate to separate the obligations between the Repository and Knowledge Supply lessons?

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

The present architectural circulate for the time being is:

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

I’ve been researching the repository sample for some time now and I are likely to see that everybody places all this logic contained in the Repository class as an alternative 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 similar for various information sources as a result of the logic is inside the particular Knowledge Supply lessons. I am frightened about having the logic cut up in numerous lessons as a result of this interprets in larger 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 likewise a protocol definition.

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

itech24 is your news, Business, Cryptocurrency, Investment, Technology website. We provide you with the latest breaking news and videos straight from the Business industry.


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Sun, 30 Jan 2022 12:44:03 GMT on The Final DeFi Wallets For 2022