The business logic layer can also be called the business entity layer, which is composed of various business entities.
Comrades can refer to the pet shop40 business logic layer, which contains many entities. For example, products:
Using System. Collections. Generic;
Using Petshop. model;
Using Petshop. idal;
NamespacePetshop. BLL {
/// <Summary>
///A business component to manage products
/// </Summary>
Public ClassProduct {
// Get an instance of the product Dal using the dalfactory
// Making this static will cache the Dal instance after the initial load
Private Static Readonly Iproduct dal = Petshop. dalfactory. dataaccess. createproduct ();
/// <Summary>
/// A Method to retrieve products by category name
/// </Summary>
/// <Param name = "category"> The category name to search </Param>
/// <Returns> A generic list of productinfo </Returns>
Public Ilist < Productinfo > Getproductsbycategory ( String Category ){
// return new if the string is empty
If ( string . isnullorempty (Category)
return New List productinfo > ();
//Run a search against the data store
ReturnDal. getproductsbycategory (category );
}
/// <Summary>
/// A Method to search products by keywords
/// </Summary>
/// <Param name = "text"> A list keywords delimited by a space </Param>
/// <Returns> An interface to an arraylist of the search results </Returns>
Public Ilist < Productinfo > Getproductsbysearch ( String Text ){
// Return new if the string is empty
If ( String . Isnullorempty (text. Trim ()))
Return New List < Productinfo > ();
//Split the input text into individual words
String[] Keywords=Text. Split ();
//Run a search against the data store
ReturnDal. getproductsbysearch (keywords );
}
/// <Summary>
/// Query for a product
/// </Summary>
/// <Param name = "productid"> Product ID </Param>
/// <Returns> Productinfo object for requested product </Returns>
Public Productinfo getproduct ( String Productid ){
// Return empty product if the string is empty
If ( String . Isnullorempty (productid ))
Return New Productinfo ();
//Get the product from the Data Store
ReturnDal. getproduct (productid );
}
}
}
Note that the data access layer of the business logic layer uses an interface, which is not hard to understand. The implementation of the data access layer may be diverse, petshop provides two different implementations: Oracle and sqlserver. However, this does not affect the logic layer. This is the power of interface-oriented programming.
Productinfo is a model that spans multiple layers. OtherCodeThere's nothing to say.
Looking at the global view, this business logic layer is actually building the business entities that may be used in many systems. Client Code directly uses these business entities, it is the bricks and wood in our model. As for the data access layer, there is no relationship between the data access layer and the system we need. Today, we may use relational databases. Therefore, to build business entities, we need to construct SQL statements at the access layer, if it is an object-oriented database tomorrow, we can really save this access layer, so the data access layer is not static, but the business logic remains unchanged.
Okay. What do I think is a good way to build a business entity? Is it to look for nouns in the system? It is not absolute. Some terms may not be worth building entities for them. My method is to first write the code of the client to use these business entities (of course, this is also Pseudo Code), which is the same as Martin's test driver, the purpose of writing the client code first is to give you a clear picture of the entity you want to build. This kind of top-down design seems to be inverted, but it is actually back-to-source, which is the correct design method.
Of course you said, the client code usage habits are different for everyone. Let me say that there is no such thing as absolute. Designing an entity is to make it more friendly and easier to use. Follow these steps to implement your design.