At present, the idea of software layering has been popularized and has also achieved good results in projects I have done. However, there are also obvious disadvantages. When dealing with changes from the bottom up, it is often necessary to perform cascade modifications, especially changes in the database structure. In addition, if an ORM platform such as nhib.pdf is used, this is a bit better.
In the complex business logic layer, objects are usually very small in granularity, which is not convenient to use at the presentation layer, and duplicate code (such as regular initialization and number of data shards) will be generated ), this increases the learning difficulty and Development workload of the presentation layer developers. In this case, the service layer (Packaging layer) is often added to the business logic layer to reduce repetitive code and unnecessary complexity.
The disadvantage of adding a service layer is also obvious: reduced flexibility.
In this example, the service layer wraps the business logic, simplifying the development of the presentation layer. The service layer packaging class requires database connection parameters. Therefore, the single-piece mode is used, static attributes are used to further encapsulate the service layer objects, and multithreading is taken into account. In this case, you only need to modify the service layer packaging class for future changes to the service layer interface.
// Service layer packaging
Public class MyUserService
{
Public MyUserService (string strConn)
{
//......
}
//......
}
......
Public class BusinewwWapper
{
Private static MyUserService m_User;
Private static string m_StrConn;
Static BusinewwWapper ()
{
// Necessary Initialization
M_StrConn = ......;
}
Private static void SetUser ()
{
Lock (typeof (SmWFM ))
{
If (m_User = null)
M_User = new MyUserService (m_StrConn );
}
}
Public static MyUserService User
{
Get
{
If (m_User = null)
SetUser ();
Return m_User;
}
}
//......
}
In fact, with a framework like Spring. NET, this is unnecessary.