RealmDb: pure architecture on Android

I appreciate RealmDb, I feel that RealmDb is closely related to the model layer. Which makes me feel that tomorrow I will need to replace some other local database than this will be a huge refactoring job.
My question is: how to achieve clean architecture with RealmDB? Any examples I can follow?

+5
source share
2 answers

Realm just makes it easy to reuse database models as your presentation models if you want. But there is nothing that would stop you from having data-level objects and looking at object-level objects, and then doing the mapping at the borders.

eg.

// Data layer public class FooEntity extends RealmObject { // Realm fields and methods... public static FooEntity fromViewModel(FooViewModel viewModel) { // Convert to entity } public static FooViewModel toViewModel(FooEntity entity) { // Convert to view model } } // View layer public class FooViewModel { // Standard POJO used by the View layer } 

In many cases, this is most likely redundant, but it will give you the desired separation.

+2
source

There are different architectures, the main purpose of which is to isolate the domain of our application from the frameworks as pure architecture, onion architecture, hexagonal architecture.

To achieve this isolation, implementation details are hidden as a data layer. The border or port is defined at the domain level that defines access to the stored data, but not knowing how it is stored, the repository template is usually used to implement this architecture requirement.

With these requirements, we will usually have a persistence model and differentiated domain objects. Sustainability models can and should be associated with the framework that we use, for example, in the Kingdom.

I leave a chart where you can better understand it graphically.

Clean architecture

0
source

All Articles