When designing an ERP program, it is necessary to extract common code into a common type library. This can reduce code duplication and increase code utilization.
However, there is a degree of doing everything, and some common code causes excessive encapsulation, but it is not good for code understanding.
Examples are as follows
Copy Code code as follows:
public class ConfigHelper
{
<summary>///Gets Whether the specified path is a valid absolute file path. </summary>
<param name= "path" >any path. OK if NULL or empty.</param>
static public bool Isvalidpath (string path)
{
Regex r = new Regex (@ "^" ([a-za-z]:) | \)) (\{1}| ((\{1}) [^\] ([^/:*?<> "" |] *))+)$");
return R.ismatch (path);
}
public static string GetString (String key)
{
return System.configuration.configurationmanager.appsettings[key];
}
}
The second method GetString, I think its encapsulation is unnecessary. Call. NET Framework has only one line of code, or a simple number of lines to encapsulate it, but it can cause an understanding barrier.
To see another method, the encapsulation of it, depending on the specific use of the scene.
Copy Code code as follows:
public static decimal Getdecimal (string key)
{
Decimal value = default (decimal);
if (decimal. TryParse (GetString (key), out value))
{
return value;
}
Else
{
return 0m;
}
}
The function of this method is to convert a string to a numeric type and, if its value is not a numeric type, return the default value of 0.
Depending on the scenario you want, this package may be necessary to reduce a lot of duplicate code.
Welcome everybody to give the opinion, I thought this getdecimal method is also superfluous, the unnecessary encapsulation.