• Post Reply Bookmark Topic Watch Topic
  • New Topic

static methods  RSS feed

 
D Tom
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm planning to create a file encryption application consisting of separate classes for the different activities like file/directory navigation, key management, actual encryption/decryption etc.

For key management, I'm creating a helper class called KeyManager that takes care of all key related activities like generating and storing symmetric keys, key pairs, generating and loading new key stores etc. All methods in this class are currently public and static so that I don't need to create an instance of KeyManager class to access its methods. I'm wondering if this approach has any drawbacks. Is there any advantage in converting all methods to non-static and creating an instance of KeyManager class to access its methods?

 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a Mickey-Mouse classification of methods somewhere on the Ranch. The question is, does your class have any instance fields which it will need? It would appear that you might need a reference to a key or key pair as a field of your class. And that key or key pair might be different for different instances, so it cannot be static. If you need that key or key pair for anything in a method, then that method cannot be static.
 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your methods does not operate on instance variables that it is not a problem to make the method static.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!