Java – declaring class abstraction is a bad design because it has only static members?

My project has a class for loading external resources (i.e. images and audio files) This class has only a few members: the HashMap field used to store resources, and the get image (Reference) method used to retrieve resources

I initially implemented singleton pattern, but later I read some criticism on the link page and considered using static members

Long after happily deciding to statically implement all the class functions, I'm doing some code cleaning In doing so, I realized that nothing could prevent me from instantiating this ResourceManager class This leads me to tag it with the abstract keyword

I've never used abstraction in this way before; I've just traditionally applied it for inheritance trees I try to use Google search to use and abuse abstraction, but all the resources I find seem to be untrustworthy, or there is no suggestion not to use abstraction in this way:

Oracle’s tutorial on abstract classes and methods. Another site discussing the keyword.

Reference from the second link: "its purpose is purely as a parent service of the class."

Is my new implementation traditional, forgivable, or just wrong?

Solution

You don't have to abstract it, just make the constructor private Abstract tells the developer that this class is for extension, which is not the case in your example

private ResourceManager() {
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>