Software Principles to keep in mind- Developer’s Commute newsletter

Hitesh Kohli
3 min readDec 16, 2023
Photo by TheMarketingHustle.com on Unsplash

Understanding the Basic Software Development Principles

One quality of a noob developer. He starts writing code without any plan in mind. One quality of a senior developer. Always have a plan before writing any code.

What kind of plan am I talking about?

No, the plan is not to bring world peace or find exoplanets.

It’s about developing production-grade apps that are maintainable, sustainable and testable. So how can we make a good production-level app with best practices?

By following simple Software principles like KISS, DRY and SOLID.

In this newsletter, I will be talking about the SOLID principle and how can we apply it in Android development. I will be breaking down these principles over time and hopefully, you can learn from them and plan your code accordingly.

Let’s start with the basics of SOLID.

SOLID has a few parts:

  • S → Single Responsibility
  • O → Open/Close
  • L → Liskov Substitution
  • I → Interface Segregation
  • D → Dependency Inversion

— — —

Do you want these topics in your Email Inbox:

Interesting facts about apps
Expert Advice
Core Concepts
Developer Stories
Apps Reviews
Human error
Code Philosophy

Additional:
- Coding Memes
- Interesting Tweets & Articles
- Motivation

— — —

Let’s start with Dependency Inversion. Dependency Inversion has certain rules that help us design better software.

→ High-level modules should not depend on low-level modules both should depend on abstractions.

→ Abstractions should not depend on details. Details should depend upon abstractions.

These two lines sound like some high-level programming stuff but it is not. Instead, you might be already using it in your code without realizing it.

High-level modules are those modules that observe the business logic to perform actions. In contrast, low-level modules are those modules that contain logic for the high-level modules. For example, Jetpack Compose UI observes the ViewModel to perform certain actions. In this example, the Compose screen forms the low-level module whereas ViewModel forms the High-level module.

According to Dependency Inversion, the High-level modules should depend on low-level modules. It means that viewmodel (high-level) should not be dependent on the jetpack screen (low-level). Instead, both should depend on abstractions like using interfaces.

Let’s explore the second line, It suggests that abstractions should not depend on details. For example, an interface should not depend on a repository. Instead, details must be dependent on abstractions.

Let me give you one more example.

Suppose we want to store token data received from an API call. We can do it in two ways:

→ Using Shared Preferences

→ Using Data Store

Suppose we are storing using shared preferences. The function used for storing is being called inside of the repository. So we can only change the function by changing the logic inside of the repository. This practice can impact the repository code.

What if we can change the storage method by changing one word?

We can inject an interface of the shared preferences class inside the repository’s constructor. And take the token data from the repository and store it using a shared preferences class. Now in future, if we want to change the storage method, we can change the interface in the constructor. To change the storage method.

APIrepo(val sharedprefencesInterface){ ------------> val datastoreInterface
-----
-----
Taking the token data from the repository
}
Class Shared  Preferences(){
---- storing token data
}
Class Datastore(){
---- storing token data
}

This is the basis of Dependency Inversion.

We will explore more parts of the SOLID principle in upcoming newsletters and see its implementation in code.

This is for today I hope you enjoyed this newsletter. If you enjoyed it please let me know and if I have written something wrong please forgive me.

Thank you for reading

Regards,

Developer Commute’s Captain

— — —

Do you want these topics in your Email Inbox:

Interesting facts about apps
Expert Advice
Core Concepts
Developer Stories
Apps Reviews
Human error
Code Philosophy

Additional:
- Coding Memes
- Interesting Tweets & Articles
- Motivation

— — —

--

--

Hitesh Kohli

I will help you build distribution with apps |Building and Designing apps| Writing Newsletters 📩| Building @Developcommute & Niwa