jeudi 6 juin 2019

Best practice to store immutable information in Java

We have an application that works with a bunch of CSV files. We need to store some information about each file - list of columns, data-types of columns, etc.

The purpose to store this information is to be able to validate the schema of a file, and also to be able to read files in a particular format, etc.

We have decided to store this information in Java since it will avoid deserializing it everywhere.

What is the best way to store such information in Java?

  1. Using enums
enum FileType {
  FileType_1(list of columns / data-types)
  ...

  List<String> Columns;
  Something Schema
}

Or should FileType be an interface, and each file type should implement that interface and store a bunch of final static constants?

Since the information is immutable, my preference is to use an enum so that we don't need to construct an object to associate a file with its type (or we use reflection, which is worse). But there are some concerns that an enum implies a level of static to the values.

Are enums supposed to be used to store this kind of information?

Aucun commentaire:

Enregistrer un commentaire