spring Spring Core Introduction to Spring Core


Example

Spring is a vast framework, so the Spring framework has been divided in several modules which makes spring lightweight. Some important modules are:

  1. Spring Core
  2. Spring AOP
  3. Spring JDBC
  4. Spring Transaction
  5. Spring ORM
  6. Spring MVC

All the modules of Spring are independent of each other except Spring Core. As Spring core is the base module, so in all module we have to use Spring Core

Spring Core

Spring Core talking all about dependency management.That means if any arbitrary classes provided to spring then Spring can manage dependency.

What is a dependency:
From project point of view, in a project or application multiple classes are there with different functionality. and each classes required some functionality of other classes.

Example:

class Engine {

  public void start() {
    System.out.println("Engine started");
  }    
}

class Car {

  public void move() {
    // For moving start() method of engine class is required
  }
}

Here class Engine is required by class car so we can say class engine is dependent to class Car, So instead of we managing those dependency by Inheritance or creating object as fallows.

By Inheritance:

class Engine {

  public void start() {
    System.out.println("Engine started");
  }
}

class Car extends Engine {

  public void move() {
    start(); //Calling super class start method,
  }
}

By creating object of dependent class:

class Engine {

  public void start() {
    System.out.println("Engine started");
  }    
}

class Car {

  Engine eng = new Engine();
 
  public void move() {
   eng.start();
  }
}

So instead of we managing dependency between classes spring core takes the responsibility dependency management. But Some rule are there, The classes must be designed with some design technique that is Strategy design pattern.