I have three classes one is Feature and other ContacstsSender and ContactsRetriever. Feature class has two methods which are common in other both classes, they have to use them. These both methods contains a few lines of codes say 6 to 10. I want to know that is it ok to keep these classes and methods where they are or just put these small methods in both classes as calling from another class time and again could cost efficiency? And in concept of memory how would it be useful to call from a class and call method locally? Thanks
I have three classes one is Feature and other ContacstsSender and ContactsRetriever . Feature
Share
What matters is not so much the location of the method as the location of the parameters used by the method in memory. But even the location of the parameters won’t matter much in 99% of the situations.
Memory wise it makes no difference (apart from the size of the class files loaded by the class loader but we are talking in hundreds of bytes here).
So avoid code duplication and you’ll be fine.
As usual with optimisation, the bottlenecks in your application are not where you think they are and you should use a profiler to find them.