It's not as though I don't understand OOP concept, and what should be done when, but sometimes I just mentally get lost in that.
What better from an example? So I needed to download a file to a temp path, I decided to get the temp path not by the normal methods of dot net, because of irrelevant reason. So I wrote my own method for this string GetTempFileSafe(string extension, out FileStream)
, nice, isn't it? But hey, wait a minute, this is not the right place for this method... This method might be used for other things. It need to be a static public method somewhere. but where? Well, I guess I'll need to open a new static class for it. Hope I'll add it more methods some other day.
So I defined public static class FileStreamUtils \\one hell of a name huh?
, and added to it my method. But hold on.. Where this class should be? Basically I can be use from any project... it has nothing to do with this specific one. So I opened a whole new library to which I called MyUtils
.
I added my static class with my one single static method into it, built the library, add the dll as a reference to my original project... and that it. (pay attention the method is more difficult to debug, because I'm using the dll rather than the original code)
Now don't get me wrong. I literally love OOP concepts and tidiness, but sometimes it just mentally exhaust me.. maybe because I work all by my own.
So what do you think? Am I just crying for nothing, and things like open an utilities library are done mostly once, and I just need to change my attitude? Or do you think that sometimes it's better not to stick to neatness that much (in my case, for example, just live the method there, and in case I'll ever need it again, move it to public use)?
Thank you very much. And please, if you somehow succeed to find a reason to vote me down, no problem, but just please leave a comment, so I'll be able not to repeat my mistakes here.
I'm always struck by how on point Robert Glass' Rules of Three are in these situations. Don't worry about reuse until you have three places where your function might fit. I always like to write the function the first time I need it. Note that I'm duplicating it the second time. And the third time do the work for reuse (refactor it into a utility library).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With