Layered, new third board layered

Source: Internet
Author: User

Layered, new third board layered

In a layered architecture, the system is layered in general, which involves the concept of vertical and horizontal directions. A large system can not simply process information in terms of business logic, it may also involve some other logic processing. Here, we cannot just abstract the logic into three layers. The three layers are one layer in the horizontal hierarchy, if you do not see the layer-3 layer when you pull the focal length of a layer, you may not find the target in the processing sub-layer of the information flow if you pull the focal length closer.

1.

Break down a large system into three business logic blocks, which is actually the three major layers I mentioned. We will narrow the focal length closer to the Child layers in business logic 1;

The big layer of logic 1 is divided into two sub-layers BLL, and DAL, which are our common business logic layer and data access layer;

The business logic layer 1 is mainly used to add, delete, modify, and query databases. abstracting it into BLL and DAL is also the three layers we are familiar;

In the other two business logic layers, you can break them down into multiple sub-layers. After the sub-layers are separated, specific implementation issues are involved,

Take the C # object-oriented language as an example. The architecture and thoughts are both methodological things, and the specific implementation is indispensable;

The layer is used to determine whether layer-by-layer Isolation is true during the development process and does not depend on each other. Therefore, the interface layer is used to separate the specific implementation layer,

We will change the BLL layer to the BLL interface layer and the DAL layer to the DAL interface layer DALI, so that BLL and DAL can implement the BLLI and DALI interfaces,

Completely separated development, which is also the interface-Oriented Programming advocated by Object-Oriented rather than implementation programming;

 

 

In the future, BLL layer problems can be completely replaced by another BLL layer, and the DAL layer is also the same; but this is an ideological thing that is not as easy as implementing the Code:

For example, blli B = new BLL (); // in general, the interface is used in this way, but it does not seem as clean as the theory suggests, we are implementing separation by adding a factory;

 

In this case, blli B = new BLLI Factory (BLLI interface type) is used. When the factory is called, the interface type is passed as a parameter, in the factory, you can use the interface type to find specific implementation objects. For example:

Public static T GetInterfaceRealization <T> (Type interfacetype)
{

Assembly ass = Assembly. LoadFrom ("Assembly name ");

Type [] asstype = ass. GetTypes ();
If (asstype. Length <= 0)
Throw new Exception ("interface manager Exception: This assembly does not have any implementation classes ");
For (int I = 0; I <asstype. Length; I ++)
{
// Obtain whether the entire inheritance chain of the implementation class has an interface type passed in;
Type oddinterfacetype = asstype [I]. GetInterface (interfacetype. Name );
If (oddinterfacetype! = Null)
{
T t = (T) System. Activator. CreateInstance (asstype [I]);
Return t; // return the interface implementation class of dynamic instantiation;
}
}
Throw new Exception ("interface manager Exception: There is no implementation class for this interface. You must first implement the interface class before searching ");
}

Because different projects in the same solution are directly referenced by each other, it is conducive to project development and debugging, however, our BLL and the caller are completely independent and there is no type of call during Program Calling. Therefore, when the solution is generated, the referenced project assembly will not be copied to the execution directory. medium, if you want to omit manual operations, you can call the object at the Implementation Layer before performing the search, in this way, when compilation is generated, the code will check that your called Project assembly will be copied to the execution directory, and will not fail during dynamic search through the interface factory;

In this way, the rule of layer-by-layer separation is thoroughly implemented.

 

Related Article

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.