So a major principle of software engineering is programming to an interface. Basically this means when creating objects we should create them based on the Abstract class and only instantiate this object with its implentation class.
Coach Obj = new TrackCoach();
Above is an example of a Coach Abstract Class object being instantiated with an implentation Class Object. Of course Obj cannot be instantiated with anything else if declared as an abstract class. So the benefit to this is if we want to apply a new implentation, we simply replace TrackCoach(); with say SoccerCoach(); And this is where Inversion of Control comes in!
Inversion of Control
Instead of manually adjusting the POJO(Plain Old Java Object) e.g TrackCoach(), we can use three methods available in Spring:
- Using an XML configuration file along with the ClassPathXmlApplicationContext class
- Using Java Annotations
- Using Java code
No comments:
Post a Comment