DEV Community

Discussion on: Use constant variable declaration across your package in JAVA

Collapse
 
climbing_dev profile image
Maciej Modzelewski

Hey Rahul, consider using enum for such cases: enum OrderStatus { COMPLETED, IN_PROGRESS, PENDING }. This gives you better type saftety and adds more context to the contants.
Even better you could create an internal enum in the Order class and expose methods like: isPending(); isInProgresss(); isCompleted(). This way the status does not need to leak to the rest of the application.

Collapse
 
ats1999 profile image
Rahul kumar

hey Maciej, you are right we can use enum for such case. But, we can also expose methods as you said.

This way the status does not need to leak to the rest of the application

We are just exposing the status codes across the package, not the status of any particular order. We can always hide the status of order from outside entity.