具有 MVP 架构的 UIKit iOS 应用程序,利用 IoC 和 DI

清洁最有价值球员

战俘黑暗.mp4


Requirements:

Functional:

  • Fetching and parsing data from API.
  • Listing Data.
  • Searching.
  • Pagination.
  • Navigation to Details view.

Non-Functional:

  • Performance:

    • Caching images.
  • Scalability:

    • Modularity.
  • Reliability:

    • Unit tests.

Low-Level Design

Low-Level Design


Design Decisions

  • UI:

    • UIKit
    • MVP Architecture
  • Principals and Patterns:

    • SOLID conformance:
      • Features are separated into modules.
      • UseCases for business logic.
    • Utilizing IoC and DI.
    • Coordinator pattern for navigation.
  • Dependency Manager:

    • Swift Package Manager (SPM)
  • Dependencies:

    • Kingfisher: Downloading and caching images from the web.

Notes:

  • Design Patterns:
    • Bridge Design Pattern ( and ) is used to avoid code duplication.BaseVCBasePresenter
    • Adapter Design Pattern ( and ) is used to easily swap HTTP clients or Data Persistence if needed (ex. instead of ).HTTPClientWatchlistDataStoreAlamofireURLSession
    • Composite Reuse Principle (CRP) ( and ) is used to compose the .DataSourcesDelegatesViewControllers
    • An Automatic DI Container (Resolver or Swinject) could be used if the project got bigger.
    • Repository Pattern could be used if local data storage is needed in the future.
  • iOS APIs:
    • DispatchGroup () is used to handle multiple async network calls.SimilarMoviesUseCase
    • Race Conditions are avoided in using a serial .SimilarMoviesUseCaseDispatchQueue
    • A Set is used over an Array in to achieve search time complexity.WatchlistDataStoreO(1)
  • To achieve better UX:
    • ActivityIndicator for each network called is used.
    • Debouncer is used to avoid unneeded search results and UI refreshes.
    • DarkMode and Landscape modes are supported.
    • Errors are handled to avoid failing silently.
    • Different placeholders are used for different image types (poster or cast).
  • All the presenters are unit tested (15 tests in total).

GitHub

点击跳转