Skip to content
ArceApps Logo ArceApps
ES

SOLID Principles: Android Examples

2 min read
SOLID Principles: Android Examples

📏 SOLID Principles in Android

SOLID is a set of 5 principles for writing maintainable OOP code.

1. Single Responsibility (SRP)

A class should have one reason to change.

  • Bad: UserActivity handling UI, Network, and Database.
  • Good: UserActivity (UI) -> UserViewModel (State) -> UserRepository (Data) -> UserRemoteSource (Network).

2. Open/Closed (OCP)

Open for extension, closed for modification.

  • Bad: if (type == A) ... else if (type == B) ...
  • Good: Use interfaces and polymorphism.
    interface Payment {
        fun pay()
    }
    
    class CreditCard : Payment { ... }
    class PayPal : Payment { ... }

3. Liskov Substitution (LSP)

Subtypes must be substitutable for their base types.

  • Bad: Square inheriting Rectangle and changing setHeight.
  • Good: Use composition or separate interfaces.

4. Interface Segregation (ISP)

Clients shouldn’t depend on methods they don’t use.

  • Bad: interface Worker { work(); eat(); } -> Robot doesn’t eat.
  • Good: interface Workable { work(); }, interface Eatable { eat(); }.

5. Dependency Inversion (DIP)

High-level modules shouldn’t depend on low-level modules. Both should depend on abstractions.

  • Bad: ViewModel depends on RetrofitUserApi directly.
  • Good: ViewModel depends on UserRepository interface. UserRepositoryImpl depends on RetrofitUserApi.

🧠 Why It Matters in Android

SOLID prevents “God Activities” and tightly coupled code that breaks when you update libraries (e.g., migrating from Gson to Moshi).

  • SRP makes ViewModels testable.
  • DIP (via Hilt) allows easy mocking.
  • ISP keeps interfaces clean.

🏁 Conclusion

Applying SOLID principles (especially SRP and DIP) is the foundation of Clean Architecture.

Share this post:

You might also be interested in

OpenSpec for Mobile Development: Spec-Driven Development in Android and Kotlin
SDD May 17, 2026

OpenSpec for Mobile Development: Spec-Driven Development in Android and Kotlin

How to apply OpenSpec in Android and Kotlin projects to keep AI agents aligned with architecture, with practical examples of change proposals, task validation, and living files.

Read more
Socratic Method Prompts: Breaking AI Sycophancy in Kotlin & Android Development
AI May 17, 2026

Socratic Method Prompts: Breaking AI Sycophancy in Kotlin & Android Development

Learn how to stop LLMs from being compliant assistants and turn them into ruthless evaluators. Discover the mathematical anatomy of Socratic prompts for Android architecture, Kotlin Coroutines, and strict Spec-Driven Development.

Read more
Clean Architecture: The Ultimate Guide for Modern Android
Architecture October 15, 2025

Clean Architecture: The Ultimate Guide for Modern Android

Demystifying Clean Architecture: A deep dive into layers, dependencies, and data flow to build indestructible Android apps.

Read more