There is a function in the project that is used only three times in several classes. Do I put this function in a common function library or in each class? Isn't it common enough to put the public function library into use, and it seems cumbersome to put it in the class? How do we deal with less-called functions? There is a function in the project that is used only three times in several classes. Do I put this function in a common function library or in each class?
Isn't it common enough to put the public function library into use, and it seems cumbersome to put it in the class?
How do we deal with less-called functions?
Reply content:
There is a function in the project that is used only three times in several classes. Do I put this function in a common function library or in each class?
Isn't it common enough to put the public function library into use, and it seems cumbersome to put it in the class?
How do we deal with less-called functions?
I think all repeated code should be put in the public place. You have already used it three times, and you will need to use it later. In addition, you can endure putting a public east and west into three classes. If you can, you can write a parent class, put this function in it, and inherit the necessary class to use it.
Just a few functions can be written as a trait.
Every code that has been repeated is extracted to form a static class method or function, because you have already repeated the code, and you have to use it again after you can't help it.