π‘ Look at this great idea to better organize constants in your code:
a constant class with inner classes to separate constants by subject.
Seven months ago I had posted the thoughts below, which came close, but listed them as 2 separate options: a constant class versus separate inner classes in each class where they would be used.
π Jannis Schreiber made the leap that brought a better solution. π
Sometimes we think a dichotomy exists but it is worth to ask "why not both?" (from the meme "ΒΏporque no los dos?").
ππΌ CONSTANT CLASS PROS:
* All constants in one place can make it easier to manage and update them.
* Simplifies the search for constants across the application.
* A single class promotes modularity and separates constants from the logic.
* Keeps consistency across the application, reduces the risk of discrepancies.
ππΌ CONSTANT CLASS CONS:
* It can become cluttered.
* Violates the Single Responsibility Principle.
* Can make it difficult to navigate within the class and find specific constants quickly.
* Creates coupling between different parts of the code.
* Changes in this class might have wide impacts and bring dependencies issues.
* It is a premature optimization and may end up as wasted effort with constants not actually reused.
ππΌ INNER Constant Class PROS:
* Can organize constants into cleaner logical groups
* Keeps related constants together and tied to their context
* Reduces clutter
ππΌ INNER Constant Class CONS:
* May add unnecessary complexity and overhead
* Makes constants harder to access, harder to be reused across multiple classes

