Some differences between IOC mode and Factory Method mode

zhaozj2021-02-12  127

"Programmer" Magazine, there is a Martin Flower's article about IOC. Read the "refactor" of Martin, so about his article must be fine to taste. But in Martin used to explain the example of IOC, I think it seems very confused. I can use a Factory Method instead of IOC implementation. So do not understand what specific differences between the two, or how the factory method is to achieve a specific implementation of IOC.

Later, I saw the article of BQ on JDON, just what I needed.

Suppose there are two classes B and C: B as the caller, C is called by the caller, and there is a call to C in the B code:

Public class b {private c concer; ......}

When the client calls B, there are different features and distins the plant mode and IOC, respectively:

The main difference is reflected in Class B code. If IOC is used, the code will not be embedded in any factory mode in Class B code, because these factory models are actually indirectly linked to C, so that IoC is completely decoupled. The connection between B and C.

The price brought to IOC is: need to be contacted between B and C at the client or other somewhere.

Therefore, IOC does not eliminate such links between B and C, just transferring this connection.

转载请注明原文地址:https://www.9cbs.com/read-6377.html

New Post(0)