Using IndexedDB on Web Browser with Well Known Design Patterns — Only with Java by Mrs. Gwitany and Dr. Jackl

Dr. Lofi Dewanto
Star Gazers
Published in
8 min readOct 28, 2020


In the article “Using IndexedDB in Web Browser — All in Java” Mrs. Gwitany and Dr. Jackl told us how we could use Java with Elemental2 to build a simple prototype based on WebAPIs for IndexedDB. This time they’ll show us how to build the already shown code to be testable and maintainable with all the Design Patterns we already know from our server-side experiences with Java.

In the server-side Java world we use following patterns all the time, so we want to use them in the Web browser apps as well:

  • Dependency Injection: we inject dependent object into a main object so that we could easily mock the injected object to be able to test the main object in a simple unit test. This is very useful especially if the dependent object uses e.g. database which can’t be booted very quickly.
  • Service and Repository Pattern: we build services and those services access data repositories to be able to call the database operations.
  • Rich Domain Model: we don’t want to build anemic domain model which contents only data, instead we also want to have some logics in it which is called rich domain model.
  • Builder Pattern: we build our object step-by-step using correct sequence of actions to be able to manage the creation of that object.
  • Mock Test: as mentioned before it is very important to be able to mock the behavior of dependent objects so that you don’t need to use real database for your unit test.

Lesson 1: to build maintainable and extensible Web browser app you need to use the known design patterns you already learned from the server-side Java.

To show how we could use the patterns Mrs. Gwitany has created a small example indexeddb-elemental2-dagger2-example based on IndexedDB which we have seen in the last article. Following libraries and frameworks are used in the example:

  • Dependency Injection: Dagger2 is designed to be flexible and uses fully static, compile-time generator for Java, Kotlin and Android.
  • Service and Repository Pattern: no special framework for Service and for Repository Pattern we use a generic Repository Pattern…