Dependency reversal

Dependency:
In the process of step-by-step refinement from top to bottom,
share pictures

The solution of big problems depends on the solution of medium and small problems,
the solution of medium problems depends on the solution of small problems, the arrow points downwards to indicate the caller Depend on the provider.

The general dependency in the object-oriented process is:
share picture

The picture shows different drivers driving different cars.
But the fact is that one driver can drive a variety of vehicles, and the principle of dependency reversal is introduced.

Relying on the principle of reversal is another way of thinking, not a denial of the idea of ​​gradual refinement from top to bottom.
Share a picture

When the Dirver class calls the drive method, the access is The Run method of IVehicle, and Car, Truck, etc. all implement the IVehicle interface.
In this way, Drive can open both Car and Truck. If it is a Car instance, it will call Run in Car, and if it is a Truck instance, it will call Run in Truck.

The same for the Driver:
share picture

< p>Extending further down is the content of the design pattern. PPT is taken from Liu Mengtie’s C# Getting Started Tutorial, thanks to Mr. Liu.

Leave a Comment

Your email address will not be published.