Reputation: 387
I'm creating a library and a silly questions comes to me, what's better (to performance and memory I mean) I create the classes using static methods (easier to use) or I create a normal class and when I'll use I create a object of that class in order to can call its methods? I'm really in doubt. Thanks.
By the way, I created a class that replace the Log class, in order to make the checking if is debug or release version before print something, this way I have not that delete every single log to release version, this works perfectly, however I was wondering if can impact on performance too (in first test, seems to me that not), anyone already do something like this?
Upvotes: 2
Views: 634
Reputation: 15615
It is a good question.
You can go with static methods if these methods do not need to access any non-static resource of the class. If they are just independent utility methods, then it is best to go with static methods.
But if you need to interact with some non-static members of the class, then you have to make an object of your class and then call the methods from it. Static methods are best to represent independent utility methods.
You have to decide what your library does and then choose the best approach. Like, if it's a logging library and has methods like Log.d(), Log.e() then it is best to go with static methods. If you need to go with the non-static approach, make sure to check the Singleton design pattern.
Upvotes: 4