Whats the best practise for desinging Utility library?

  • Thread starter Thread starter Gayan19911212
  • Start date Start date
G

Gayan19911212

Guest
I am designing utility library to pass log information & results such as results of every method execution time (this is one purpose out of all). At present, I have built my library and with a static class so that when developer wants to pass the log, it would call this static class method and pass information. I have seen many like this built in .Net libraries

Inside this static library, I have one private static variable and few static methods. One method (Named 'SetUp') is to create an instance of this static variable & other methods use this variable. To avoid concurrency, some suggests to have that class designed as normal class so that each time developer create an instance use that instance instead of using same instance across the application. Moreover, having this kind of implementation means no more additional methods to do set up an instance.

However, some developers would like to have this library built in dependency injection design pattern and register this as a singleton dependency so developers would call this in their constructor and assign to a private variable in their class to use.

My questions are as follows.

  1. Will there be memory problem as static would be written in heap and if I use singleton, i have one reference in the heap and multiple variables in stack link with one heap slot?
  2. Technically decoupling this would allow the developers to have their own development separate from its users. Is it more beneficial rather than the fact that developer are asked to develop in this pattern?
  3. If I'm not wrong, singleton's life time as long as application is alive. Will it be same for static class and variables inside the static class?
  4. What is best way to implement utility library?

Your opinion is highly appreciated.

Thanks in advance

Continue reading...
 
Back
Top