Using Hexagonal Architecture for Mobile Applications

Architectural Goals

Overview

  • Testability
  • Separation of application and domain logic
  • Loosely coupled User Interface
  • Independence
    • of external frameworks
    • of external agencies

Mobile Applications

  • No different goals from general applications
  • Difference in testability
  • Existence of code not runnable on development hardware

Architectural Choices

Overview

  • MVX (MVC, MVVM, MVP, MVU, …)
  • Mobile-only Architecture
  • General Software Architecture

MVX

  • Not an Architecture but a high-level design pattern
  • Not sufficient for non trivial apps
  • May be combined with a software architecture

Mobile-only Architecture

  • Often OS specific
  • Often tightly integrated with only one shape of MVX

Software Architecture

  • Not clear if fitting for mobile applications
  • Scant research

Choosing a Software Architecture

Overview

  • BCE (Boundary-Control-Entity)
  • DDD (Domain Driven Design)
  • Hexagonal Architecture (aka Ports and Adapters)
  • Onion Architecture
  • Clean Architecture

Clean Architecture

  • Very popular
  • Many misleading mobile implementations

Hexagonal Architecture

  • Shares base with clean architecture
  • Easy to implement and extend

Considerations for Mobile

Overview

  • Modularity
  • Dependencies
  • Concurrency
  • Platform Dependency

Modularity

  • Seperate into packages
  • Use built-in approach

Dependencies

Either

  • Dependency Injection Framework
  • Manually configurable dependencies

Concurrency

  • Use newest built-in general approach
  • Should be part of the ports

Platform Dependency

  • Application is always independent
  • UI may be dependent
  • Infrastructure should be split into dependent and independent parts

Conclusion

  • Most mobile applications should use a software architecture
  • Hexagonal Architecture is recommended
    • Achieves architectural goals
    • Flexible
    • Extendible
  • Mobile specific challenges can be addressed