Problems in common code based on ERP programs and solutions for excessive encapsulation inconvenient maintenance _ practical skills

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.