Image for post
Image for post

I will try to mention some software design topics which I think are important. These are:

  • Law of Demeter
  • Single Responsibility Principle
  • Composition over Inheritance
  • Primitive Obsession
  • Listen to Tests
  • Use Dependency Injection Technique

Law of Demeter(LoD)

LoD is a design guideline for developing software whose rules and benefits can be summarized as:

Rules (based on Wikipedia):

  • Each class must be able to access to another class only the information and resources that are necessary for its legitimate purpose.
  • Each unit should have only limited knowledge about other units.
  • Each unit should only talk to its friends; don’t talk to strangers.

Benefits:

  • It gives full control over class properties. You cannot change any property from outside of its class context. …


The extension functions should have a task related to the responsibility of the respective class. One of the most common mistakes made by developers is to write extension functions like a utility function. Here is an example to explain this better:

fun String.validateEmail(): Boolean {
//validation process
return result
}

These types of functions should not be defined as extension functions. Storing the e-mail information as String does not mean that String class is associated with the e-mail information. Instead this validation should reside in a class like EmailValidator.

class EmailValidator {
fun validate(email: String): Boolean {
//validation process
return result
}…

About

Güneş Maboçoğlu

Senior Android Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store