Get the App
SLTechnology News&Howtos  ›  Development  › 

Based on the problems in the common code of ERP program and what to do if excessive encapsulation is not convenient for maintenance

Shulou Source: shulou.com Published: 2022-06-03 05:39:02 11月17日 Update

This article is to share with you about the problems in the common code of ERP-based programs and what to do if excessive encapsulation is not convenient for maintenance. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

When designing an ERP program, it is necessary to extract common code into a common type library. This can reduce code duplication and improve code utilization.

However, there must be a limit to everything, and some common code causes excessive encapsulation, which is not conducive to the understanding of the code.

Examples are as follows

Public class ConfigHelper

{

/ Gets whether the specified path is a valid absolute file path. / / /

/ Any path. OK if null or empty.

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. The code that calls the .NET Framework has only one line or a simple number of lines, and encapsulating it can cause obstacles to understanding.

Let's take a look at another method, the encapsulation of it should be based on the specific use scenario.

The copy code is 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 return the default value of 0 if its value is not of numeric type.

Depending on the scenario, this encapsulation may be necessary to reduce a lot of repetitive code.

Thank you for reading! About "based on the ERP program public code problems and excessive encapsulation is not convenient to maintain how to do" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Tags: Code encapsulation program method type what to do problem necessity content scene number more article good practical one line utilization function only characters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple Shulou Information Microsoft vpn