Skip to content

Lombok Migration

rustie edited this page Mar 17, 2019 · 1 revision

Motivation

We have a lot of boilerplate code for getters, setters, and constructors. And all of this currently melds inelegantly with our model functionality. Lombok is an annotation extension for Java that lets us write a lot less code, and also enforces some of the modularity we're aiming for. More info here: Project Lombok

Usage

Besides having lombok in gradle for the application build, all developers also need to install Lombok on their Android Studio instances. Information here: Android

Design

Not much to design here except see some of the patterns we use in Lombok and discuss their vanilla Java equivalents:

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class DiningHall extends FoodPlace{...}

The above code snippet creates getters and setters for each member of DiningHall, and also creates the necessary constructors. Some of our objects in domain have a lot of members, so you can imagine how much code we save.

@Builder
public class Library implements Comparable<Library>{...}

The above snippet defines a builder class for Library objects, meaning that we can set members of library instances independently of object creation. This helps with modularity and keeps us from having to write huge constructors, or having to create the object and then calling each of its setters. More info here: Builder pattern - Wikipedia

@UtilityClass
public class FirebaseCollectionNames {...}

Utility classes define some useful constants to use for the rest of the application. It disables instantiating and makes all members final, public, and static. This particular class is used to keep track of collection and table names for Firestore.

Clone this wiki locally