Monday, October 16, 2023
HomeiOS Developmentios - is it higher to have flat or deep dependency graph?

ios – is it higher to have flat or deep dependency graph?


I’m going through a design resolution about dependencies graph design. I am engaged on iOS and Swift, nevertheless it must be a common downside.

Choice 1 is that this:

I’ve a MyApp class, which relies on a BookManager (primarily answerable for parsing logic), which additional relies on BookService that talks to my server. MyApp is aware of nothing about BookService:

class MyApp {
  non-public let bookManager: BookManaging

  func updateRawBooks(rawBooks: [String]) {
    bookManager.updateRawBooks(rawBooks)
  }
}
class BookManager: BookManaging {
  non-public let bookService: BookServicing

  func updateRawBooks(_ rawBooks: [String]) {
    let books = helper_parseBooks(rawBooks)
    bookService.updateBooks(books)
  }

  non-public func helper_parseBooks(_ rawBooks: [String]) -> [Book] {
    // numerous logic right here
  } 
}

class BookService: BookServicing {
  func updateBooks(_ books: [Book]) {
    // ship to server
  }
}

Now I’m contemplating altering it to a extra flat dependency DAG, the place MyApp relies on each BookParser and BookService straight, however the subcomponents don’t discuss to one another:

class MyApp {
  non-public let bookParser: BookParsing
  non-public let bookService: BookServicing
  func updateRawBooks(rawBooks: [String]) {
    let books = bookParser.parse(rawBooks)
    bookService.updateBooks(books)
  }
}

class BookParser: BookParsing {
  func parse(_ rawBooks: [String]) -> [Book] {
    // numerous logic right here
  }
}

class BookService: BookServicing {
  func updateBooks(_ books: [Book]) {
    // ship to server
  }
}

From what i can inform, method 1 is deeper dependency DAG, whereas method 2 is extra “flat” design. I’m questioning which is best?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments