dimanche 10 janvier 2021

Where to add magic numbers in my project? [closed]

I have a lot of magic numbers and strings in my project and I would like to replace them with constants. The thing is I remember I used, a lot of time ago, a class to hold all the constants that I would call in the code statically. It is a university project and I need to use Java design patterns.

I would like to know what's the best way to write the constants given the fact that many magic numbers are used across different classes, so I don't want to declare constants locally in each class.

I've read about resource files implemented via singleton classes, but I can't figure out why using a singleton class that makes calls to it longer than needed.

I'm writing code in Java for the server and Android for the client in case you need this info.

Aucun commentaire:

Enregistrer un commentaire