Why is it called Rely on the reverse, how a reverse method?

For example, eating chocolate:

public interface IChocolates{}

public class Oreo implements IChocolates {}

public class Dove implements IChocolates {}

public interface Person { void eat( IChocolates chocolates ); }

The above example of human chocolate produced dependence, man eating behavior depends in fact nothing to do with chocolate, chocolate appears before existed, so eating action should be dependent on the concept of internal interfaces of the man himself, this interface ownership should belong to the people, the concept should be edible (edible). So people dependency on chocolate should be inverted dependency on edible chocolate interface . After this inversion has better scalability for people, not only can eat a variety of chocolates, you can also eat biscuits, rice, fish, and so anything else to eat.

public interface IChocolates extends IEdible{}

public class Oreo implements IChocolates {}

public class Dove implements IChocolates {}

public interface Person { void eat( IEdible edible ); }

Reprinted from: https: //www.jianshu.com/p/4e268c90e720

Published 42 original articles · won praise 16 · views 3383

Guess you like

Origin blog.csdn.net/qq_41542638/article/details/105084307