Usages of Factory Method for Data Source Layer (Local/Remote - Repository) with DI & MVVM [Android].

Overview

Usages of Factory Method for Data Source Layer (Local/Remote - Repository) with DI & MVVM [Android]

Stacks:

  • MVVVM
  • DI (Hilt)
  • Factory Method (Design Pattern)

When & Why?

Factory Method

Is a creational design pattern that is concerned with the creation of objects in an application. As the name suggests, the factory method pattern makes use of classes that acts as factories to create objects. This pattern favors method invocation instead of making direct constructor calls to create objects.

In the factory method pattern, you provide an interface, which can be a Java interface or an abstract class to create objects. A factory method in the interface defers the object creation to one or more concrete subclasses at run time. The subclasses implement the factory method to select the class whose objects need to be created.

When?

In our Android Project, we have local, or remote data source (or both). For clean code & testibility purpose we keep our business logic sperate from the Feature layer. From the Feature layer, we call respective repository (or data source) to execute the business logic and notify about the result.

In such case, in terms of Enterprise or Large Scale application, we might have lots of Repository object across the application and client should not manually instantiate the objects by its own. So, the object creation process for the Repository Objects manage by a Factory, where it's responsibility to create the concrete objects for the client, based on the requested object type.

In this example project, we are creating the RepositoryFactory object in the under SingletonComponent [SingletonModule], and providing the request objects to the dependent under ViewModelComponent [RepositoryModule], where RepositoryModule use the RepositoryFactory object's instance provided by SingletonModule to initialize the requested object to the dependent.

You might also like...
An Open-Source repository that contains all the Android Dev and Kotlin concepts and several projects on android ranging in difficulty making this repo completely beginner-friendly.
An Open-Source repository that contains all the Android Dev and Kotlin concepts and several projects on android ranging in difficulty making this repo completely beginner-friendly.

An Open-Source repository that contains all the Android Dev and Kotlin concepts and several projects on android ranging in difficulty making this repo completely beginner-friendly. The main aim of this repository is to help students who are learning Android Development or preparing for an Android Developer role-based job.

Repository ini berguna untuk menyimpan kode yang dibutuhkan untuk membuat sebuah Aplikasi Android yang memiliki ListView yang menggunakan Custom Adapter dan Mengambil data dari Database secara CRUD.

AndroidListView Repository ini berguna untuk menyimpan kode yang dibutuhkan untuk membuat sebuah Aplikasi Android yang memiliki ListView yang mengguna

:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

A news app made using android studio in Java with features like favourite news, Location detector for local news, and especially made with HUAWEI APIs

HuaweiGlobalNewsApp A news app made using android studio in Java with features like favourite news, Location detector for local news, and especially m

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.
RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database. Arch

Wallpaper Battle A combined online and local HD wallpaper file manager
Wallpaper Battle A combined online and local HD wallpaper file manager

Resplash Resplash is powered by Unsplash.com The internet’s source of freely-usable images. Powered by creators everywhere. Browse 1M+ high-res photos

Sync floder from drive to local storage

GDrive #refrence and steps to upload - https://developers.google.com/drive/api/v3/manage-uploads to download - https://developers.goo

YourStore app made in Kotlin for Local e-commerce. made during ASJ, Developer Students Club, BIT Mesra
YourStore app made in Kotlin for Local e-commerce. made during ASJ, Developer Students Club, BIT Mesra

Android-Study-Jams YourStore , Vocal for Local Problem Statement: Over past two years, local businesses have faced lot of troubles due to Covid-19 and

Loco-strings-sync - A custom Gradle Plugin useful to sync loco string resources to local projects

loco-strings-sync A custom Gradle Plugin useful to sync loco string resources to

Owner
Romman Sabbir
Software Engineer (Android) | Backend Developer | Tech Lover | Music Producer
Romman Sabbir
Clean architecture dictionary app fetching remote data with local caching

ComposeDictionary Clean architecture dictionary app fetching remote data with local caching Installation Clone this repository and import into Android

Timothy Serem 2 Feb 19, 2022
ICSx⁵ is an Android app to subscribe to remote or local iCalendar files (like time tables of your school/university or event files of your sports team).

ICSx⁵ ICSx⁵ is an Android app to subscribe to remote Webcal feeds / iCalendar files (like time tables of your school/university or event files of your

bitfire web engineering 60 Dec 28, 2022
Environmental-Monitoring-Android-App - This Android App is used to monitor environmental parameters data from remote sensors

Environmental-Monitoring-Android-App - This Android App is used to monitor environmental parameters data from remote sensors. Parameters includes but not limited to temperature, humidity, air quality, level of Ionizing radiation, ...

Francisco Pascal Elias TAMBASAFIDY 0 Jan 4, 2022
Movies-db-example - Sample Android application that loads movies data from a remote server

Movies Application Sample Android application that loads movies data from a remo

Bilal Ibrahim Hairab 0 Feb 8, 2022
An easy, cross-platform method of keeping track of other people's timezones

TimezoneDB TimezoneDB is an easy, cross-platform method of keeping track of others' timezones. This project is inspired by PronounDB, and we'd like to

Synapse Technologies, LLC 13 Nov 16, 2022
when you use restful api and network get disconnect you have to store your data local for make your app faster and work on ofline mode

AppArchitectureOflineMode when you use restful api and network get disconnect you have to store your data local for make your app faster and work on o

Kareem-Mansy 3 Jun 20, 2021
remote technical interview Android challenge app

Android challenge We would like to learn more about how you approach a challenge as an Android Engineer. There is a simple app that isn’t made with be

GetYourGuide 0 Jan 9, 2023
The application is a PoC that helps in identifying modern bankers, potentially malicious and remote controlling applications abusing Android AccessibilityService.

Motivation Project aims to help in: identifying keyloggers and events hijacking malicious applications such as Anubis/TeaBot, identifying a "fake bank

Krzysztof Pranczk 33 Dec 9, 2022
PortalController - A rudimentary TeamViewer-like remote control app for Android, using ws.

PortalController A TeamViewer-like app for Android-to-Android remote control, using node.js and websockets (ws). Some insight The reason I call it rud

Mike Anderson 10 Dec 15, 2022
This component allows you to interact with remote machine via SSH. You can execute commands or run scripts located on that machine

th2 act ssh (1.2.0) Overview Provides user with the ability to execute specified scripts or commands with the parameter he needs Custom resources for

th2 1 Dec 18, 2022