Comparison of non-intrusive and intrusive Java code

Intrusive (introduced or inherited other packages or frameworks)

The superficial understanding is that other codes have been embedded in your code. These codes may be the framework you have introduced, or you may inherit them through interfaces, so that you can have some functions that invade the code. So we call this code intrusive code. Intrusive makes user code dependent on the framework. These codes cannot be used outside the framework, which is not conducive to code reuse.

The advantage of the code when intrusive: Intrusive allows users to better integrate with the framework, making it easier to make fuller use of the functions provided by the framework. 

Disadvantages: The code outside the framework cannot be used, which is not conducive to code reuse. Refactoring code is difficult to rely on too much.

 

Non-intrusive (no dependence, independent research and development)

Contrary to intrusive, your code does not introduce other packages or frameworks, it is completely self-developed.

Advantages: The code can be reused and is easy to transplant. Non-intrusive code does not have too many dependencies and can be easily migrated to other places.

Disadvantages: But the way to interact with user code may be more complicated.

Non-intrusive also reflects the design principles of the code: high cohesion, low coupling

 

Comparison of non-invasive and invasive:

Non-intrusive design: A client's code may include framework functions and client's own functions.

Intrusive design: the designer "pushes" the framework functions to the client, while non-intrusive design means the designer "takes" the client functions into the framework.

Intrusive design sometimes shows that the client needs to inherit the classes in the framework, while non-intrusive design shows that the client implements the interface provided by the framework.

The biggest drawback of intrusive design is that when you decide to refactor your code, you find that the code you wrote before can only be thrown away. This is not the case with non-intrusive design, as the code written before is still valuable.
 


 

Guess you like

Origin blog.csdn.net/LOVE_Me__/article/details/104960356