Open In App

Design Patterns in Android with Kotlin

Design patterns is basically a solution or blueprint for a problem that we get over and over again in programming, so they are just typical types of problems we can encounter as programmers, and these design patterns are just a good way to solve those problems, there is a lot of design pattern in android. So basically, they are three categories as below:

  1. Creational patterns: How you create objects.
  2. Structural patterns: How you compose objects.
  3. Behavioral patterns: How you coordinate object interactions.

Now we are going to discuss the most important design patterns that you should know.



1. Creational Patterns

These are the design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation. These are the design patterns are come under this category.

Let’s quickly talk about them:



Singleton:




object eSingleton {
  fun doing() {
    // ...
  }
}

for accessing member of singleton object you can call like this :

eSingleton.doing()

Builder:

Factory:

Dependency Injection:

2. Structural Patterns

These design patterns are all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object patterns define ways to compose objects to obtain new functionality.

Facade:

Adapter:

Decorator:

Composite:

Protection Proxy:

3. Behavioral Patterns

Command:

Observer:

Strategy:

State:

Visitor:

Mediator:

Memento:

Chain of Responsibility:


Article Tags :