Clean Architecture with MVVM

Hasnain Haider K Niazi
3 min readMay 14, 2018

--

In this , we will discuss the Clean architecture for iOS application using DDD, TDD and MVVM especially.

Clean Architecture :

Achieve a high-level separation of concerns by layering. Clean Architecture looks like a very carefully thought and effective architecture. It makes the big leap of recognizing the mismatch between Use Cases and Entities and puts the former in the driving seat of our system.it also aims for a maximum independence of any frameworks or tools that might stay in the way of application’s testability or their replacement.

  • Entities: which contain enterprise-wide business rules.
  • Use Cases: which contain application-specific business rules.
  • Interface Adapters: which contain adapters to peripheral technologies. Here, you can expect MVC, gateway implementations
  • Frameworks & Drivers: which contain tools like databases or framework. By default, you don’t code too much in this layer, but it’s important to clearly state the place and priority that those tools have in your architecture.

Benefits of a Clean Architecture :

  • Flexible
  • Testable
  • Easy to understand
  • High Maintainability
  • Could play well with best practices like DDD
  • Screaming — Use Cases are clearly visible in the project’s structure

Drawbacks :

  • Complexity
  • Learning Curve : it’s harder to grasp than the other style
  • Indirect — there will be a lot more interfaces than one might expect (I don’t see it as necessarily bad, but I’ve seen people pointing this out)
  • No Idiomatic Framework Usage — the dependency rule is relentless in this area
  • Heavy — in the sense that you might end up with a lot more classes than you currently have in your projects (again, the extra classes are not necessarily bad)

When to Use Clean Architecture :

When to Use Clean Architecture : Is the team skilled and/or convinced enough Will the system outlive major framework releases? Will the system outlive the developers and stakeholders employment?

Application :

  • Delivery pattern e.g (MVVM, MVC, MVP)
  • Place for your UIViews and UIViewController
  • Completely independent of the Platform

Platform :

  • Concrete implementation of the Domain
  • Does hide all implementation details

Domain :

  • Basically what is your App about and what it can do (Entities, UseCase etc).
  • it doesn’t have implementations apart from entities

Project Structure :

Xcode workspace :

Download Sample Project

Reference :

https://github.com/sergdort/CleanArchitectureRxSwift

http://pguardiola.com/blog/clean-architecture-part-2/

--

--

Hasnain Haider K Niazi

 iOS Developer & Certified Scrum Master | Mobile Apps Expert | Jira & Confluence Expert | SAFe Agilist® | Remote Team Leadership | DevOps | AWS