Reputation: 2280
Source code of sdk saying that com.amazonaws.services.cloudfront.CloudFrontUrlSigner
is an enum
type.
Why they did not implement this as a normal java utility class; e.g. class CloudFrontUrlSigner
with public static
methods?
is there any major reason for using enum
or just they designed it like that.
Upvotes: 1
Views: 236
Reputation: 5563
Checking on the source of class you're mentioning seems to indicate that CloudFrontUrlSigner
is merely a utlity class, exposing a few public static methods. Said methods are public and static, essentially working as utility methods, which accept a few arguments, do some post processing on them and then return something (in this case a String
).
Thus, as mentioned above the core functionality on this class is essentially a utility helper class. With that in mind, one has to take into account the best practices when creating any utility class. The main revolves around the notion of avoiding inadvertent instantiation of the class in question.
With this in mind assume what actions the developer would need to have taken to ensure this had they had chosen to implement this with a normal class. They would have had to declare the class as final
(to avoid inheriting), they would have put in place a private constructor and then create all the public methods.
Choosing though to use an enum
pretty much offers all the above out of the box. You can't inherit from an enum
nor can you instantiate with new
.
To sum up, they have chosen this in order to seemingly abide with the best practises of creating a utlity class. Ideally, for me I would go with the same enum
concept but would rather have a singleton service with the said methods.
Upvotes: 2