PickMe

PickMe's ViewModel Manager Pattern: How We Tamed a 2000+ Line ViewModel Into Clean, Testable Code

Original post The ViewModel Manager Pattern: How We Tamed a 2000+ Line ViewModel Into Clean, Testable Code

Article Summary

Chamod Lakmal from PickMe Engineering turned a 2,100-line ViewModel nightmare into 350 lines of clean, testable code. His team's test coverage jumped from 12% to 87%, and onboarding time dropped from 2 weeks to 2 days.

PickMe's checkout feature had become unmaintainable: a single ViewModel with 18 dependencies, 50+ StateFlows, and 2,000+ lines of tangled business logic. The team introduced the ViewModel Manager Pattern, extracting domain-specific logic into focused, injectable classes that share the ViewModel's lifecycle while maintaining clear separation of concerns.

Key Takeaways

Critical Insight

The ViewModel Manager Pattern uses composition to extract domain logic into ViewModelScoped classes, transforming massive ViewModels into clean coordinators that are 86% easier to test and dramatically faster to understand.

Continue reading

What This Article Covers

Problem

PickMe's checkout ViewModel grew to over 2,000 lines with 18 dependencies and 50+ StateFlows scattered throughout. Testing became nearly impossible with only 12% coverage, and the team dealt with constant merge conflicts.

Solution

Chamod Lakmal split the code using the ViewModel Manager Pattern. Six focused classes took shape: ProductManager, CartManager, PaymentManager, OrderManager, ShippingManager, and AnalyticsManager. Each one handles a single responsibility.

Impact

Test setup went from 85 lines down to 12 lines, an 86% reduction. Test coverage jumped to 87%. New developers got up to speed in two days instead of two weeks, and the code became much easier to understand.

The article includes complete code examples showing how to build your first Manager step-by-step, plus a practical migration strategy for refactoring existing monster ViewModels without a risky big-bang rewrite.

This page summarizes “The ViewModel Manager Pattern: How We Tamed a 2000+ Line ViewModel Into Clean, Testable Code” by PickMe, published Dec 23, 2025. All credit for the original work goes to the authors.

Read the original on medium.com (opens in new tab)

AI tools for Android

Browse all AI tools →