Java : IoC / DI / AOP
A recap of the concepts in Java: IoC, DI, and AOP.
IoC (Inversion of Control)
- Spring has control and does not need to create new instances in the class itself.
- To achieve the purpose of decoupling, rely on abstractions rather than instances
-Use some Annotation to achieve
DI (Dependency Injection)
- One of the implementations of IoC
- For example,
@Autowire
finds the object from the container and injects the properties
AOP (Aspect-oriented programming)
- Insert the program without modifying the other ones
- To intercept method calls, object instantiations, or exception handling at runtime
- If the logic, transactions, validations, or records of different apps must be written in every process (especially in business logic), it will lead to high maintenance costs
IoC and DI can be regarded as the design principles of OOP, while AOP solves the problem of OOP being too class-oriented and focuses the solution on aspect.