Take layer three as an example:
Create an object of the DAL layer in the BLL layer
Iuserdal Userdal = Dalabstractfactory.createuserdal ();
That is, the correlation between layers is minimized, so it is easy to think of referencing a third party as intermediate media.
This leads to the interface, which is used to receive an object from the other layer in the layer when it is created, (this interface is the interface of this object, such as the object is Userdal, the interface is Iuserdal)
This enables decoupling of the left of the equation from the DAL layer, and on the right, we cannot directly create an instance of the object. This is still coupled, so the concept of a factory is introduced,
In essence or through a third party to help us do this action, that is, to create the object.
This enables both sides of the equation to be decoupled.
But looking back, what is the purpose of decoupling?
is not to reduce the maintenance cost and readability of the code, the readability is put aside first.
Then the two layers are decoupled, but in the factory is directly created objects, although the code is very few, just create objects, but the project a large, there are many objects, is still very cumbersome to maintain.
We think that there is a way to create objects in the factory This action is also encapsulated, so that when the time to modify, modify a small piece of the place can be.
So, we thought about using the configuration file
Place the assembly (DLL) that the object belongs to, and the namespace in the appsettings node of the configuration file.
It then uses reflection (Assembly) to load the assembly, with the object being created.
The fact is that we would have been in the factory manual two actions (add DLL reference +new an object) became dynamic.
We call this factory model an abstract factory.
Summary:
Decoupling, it is clear that when the user's needs change, as the first-line labor of us, for themselves in the maintenance of code when the trouble, so in the beginning of the design framework, the design of a better, this good estimate is the original generation of programmers fell out of the pit after the spiritual sentiment it.
Then focus on the code itself, presenting a large part of the object-oriented nature. That is, inheritance, encapsulation, polymorphism. This is only a small part of the framework that is built around this feature. One thing, though, is the personal experience: not to use these features, to put them in a frame,
But for a better framework to build, and the need to use these features, so that these features, we are in use.
What's wrong? Please point out the common progress.
Understanding of decoupling