Posts for: #Design Patterns

Android Presentation Patterns: MVI

Android Presentation Patterns: MVI

MVI isn’t a single ready-to-implement pattern; it’s more of a spectrum. This post delves into its diverse range, from basic MVVM patterns to intricate Redux-like state management, emphasizing the importance of grasping its principles for effective implementation tailored to specific project needs.

[Read more]

Command Pattern in Kotlin

Command Pattern in Kotlin

The Command pattern wraps the request into a specific object that has all the information necessary to perform its task. You can think of it as the next stage of refactoring, where at first we extract the code to a separate method, and then to a separate object, taking the arguments needed to execute the request in the constructor.

[Read more]

Mediator in Kotlin

Mediator in Kotlin

The Mediator’s job is to organize communication between close classes. The Mediator pattern cuts out dependencies between components. It takes over the interaction between them, becoming the main communication hub for a group of classes. There is a reverse of the controls because components are now just telling ‘what happened’ instead of telling others to ‘do something’. It can be found e.g. in the form of ViewModel in Android, where it separates UI interactions from data model changes.

[Read more]

Adapter Pattern in Kotlin

Adapter Pattern in Kotlin

The Adapter or Wrapper Pattern allows you to translate one interface into another, expected by the client class. It is especially useful when the adapted object comes from 3rd party library, and you do not want to make your system depending on that interface, creating the so-called anticorruption layer. Adaptee interface changes will only affect the Adapter and not the rest of the code.

[Read more]

Facade Pattern in Kotlin

Facade Pattern in Kotlin

The facade allows you to hide the details of the module from clients. It ensures compliance with Law Demeter. Using the generic interface and various implementations greatly simplifies testing. It blends well with other patterns like Strategy, Template Method, or construction patterns, allowing configuration of the object available for the clients. The facade is a good entry point for libraries, giving customers access to high-level functionality and hiding all internal logic and classes.

[Read more]

Strategy Pattern in Kotlin

Strategy Pattern in Kotlin

The Strategy pattern creates a family of algorithms, enclosing the differing logic in separate classes while hiding it from clients behind the interface. It enables the interchangeable use of implementations. The use of the strategy simplifies the customer code, avoids code duplication and conditional statements. Significantly simplifies testing - by separating client testing from strategy algorithms.

[Read more]