SlideShare une entreprise Scribd logo
1  sur  3
In this tutorial we will cover spring framework and we will learn how to use spring frame work.
What is spring framework: -It’s actually a lot of things put into one.Spring is really popular for dependency
injection.
Dependency Injection: - this is sometimes called as dependency called as dependency inversion, and
definitionis “how you will decouple conventional relationship between objects that are related to each
other”i.e. one is dependent on other.
The idea is to decouple the dependencies so that they are not tied to each other. I will take an example to
explain what it means.
Example: - I have a drawing application that draws different shapes like “Circle”, “triangle”, “Square” etc..
1. I have a circle classit has a“draw ()” method.
2. And I have a triangle class that also has a method “draw ()”.
3. Now I can use these objects circle or a triangleto draw a shape onthe screen.
4. Let’s assume I have an application class.
a. I can instantiate circle objects inside this class and I can also instantiate triangle object
inside this class.
b. So code would be something like this
c. Now let’s say I don’t want my application to be tied specifically to these objects and I want
to use polymorphism.
d. Now the question is how will I use polymorphism here?
The whole Idea of using polymorphism is to have some type of interface class or some
parent class.
The example of using polymorphism is here
1. Let’s say I have a circle object and I have a triangle object both have similar draw method
2. Now I will have a “Shape” interface or a “Shape” parent class that has a draw method.
3. Now I will inherit both “Circle” and “Triangle” class from “Shape” Interface
4. Now In my application class I will write code something like this
5. Here I am calling “shape.draw()”If shape has a triangle it will call draw method from
triangle
6. So this is the polymorphism here, we are calling polymorphism, instead of calling method
of the objects, I have a handle of parent class and I will call the “draw” method of parent
class. The parent could be an abstract class or it could be an interface.
7. I don’t know which object I have when I am calling “shape.draw()”
8. But here I am still tying “circle” and “triangle” objects inside “application” class.
9. So application class always know whether it is a triangle or a circle.
10. So will go one step further and I will use “Method parameter”
11. In this code you can see that somewhere in class we are calling class “new Triangle ()”.
12. Somewhere in the class we have to call “myDrawMethod(shape)“ and pass shape object
13. So we are still tied to class name, we are not free from in it.
We will take a step further
We will move creation of object outside the class and class will not know the shape its
drawing, the class will just have a shape, then we will expectsome other class to provide the shape for
us.
We want to have shape object instead of triangle object inside the class.
We will tell another class/object to add this triangle class to application.
1. We will create a drawing class, this class will have class member variable called shape, it
will be member variable of type shape, assume I will have a code like this –
2. I will have a private shape object.
3. And then I will define a setter “public setShape (shape)” and I will take a shape as
parameter.
4. Shape can accept anything like “circle”, “triangle”, “square” etc…
5. Whatever shape object is passed it will set the variable Shape (Member variable
Shape)inside the class.
6. Now I have a “drawShape” method this will call draw()method of class Shape note that
this does doesn’t do initialization. (you don’t see a new Shape here)
7. The drawing is gonna assume that something will instantiate that and will provide that
object to this class.
8. Now we have removed the dependency of triangle or a shape, in order to draw a triangle
you don’t have to modify the Shape class. All you need to do is pass a shape type(i.e
Triangle or circle.. etc.) to setter setShapeand then call drawShapeit will draw the desired
shape.
Example
9. The whole idea is you don’t have to modify the drawing class.
10. You are separating the dependency out from the class, the drawing class doesn’t really
now that on what it is dependent, the advantage is that “if what it has to draw is changes
you don’t have to modify the drawing class because it doesn’t really know in first place”
11. You can make drawing class to draw all kinds of shape without modifying the base class.
12. Reason – the dependency ofDrawing class to a shape object is not owned by the Drawing
class. The Drawing class doesn’t own the relationship of the actual shape.
13. The dependency of drawing class is injected by the desired shape class. Dependency of
Drawing class is not hard coded but it is injected by an external entity.
This is all about dependency Injection

Contenu connexe

Similaire à Learn Spring Framework and Dependency Injection in 40 Steps

Abstract vs Concrete Classes.pptx
Abstract vs Concrete Classes.pptxAbstract vs Concrete Classes.pptx
Abstract vs Concrete Classes.pptxMahmoodAlashqar
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptxHailsh
 
Alice 3
Alice 3Alice 3
Alice 3frcol
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS ConceptRicha Gupta
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classesAnup Burange
 
Contoh Factory pattern
Contoh Factory patternContoh Factory pattern
Contoh Factory patternFajar Baskoro
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdffaxteldelhi
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in pythontuan vo
 
The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189Mahmoud Samir Fayed
 
08review (1)
08review (1)08review (1)
08review (1)IIUM
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.conceptstahir266
 
The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196Mahmoud Samir Fayed
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 

Similaire à Learn Spring Framework and Dependency Injection in 40 Steps (20)

Abstract
AbstractAbstract
Abstract
 
Abstract vs Concrete Classes.pptx
Abstract vs Concrete Classes.pptxAbstract vs Concrete Classes.pptx
Abstract vs Concrete Classes.pptx
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptx
 
Alice 3
Alice 3Alice 3
Alice 3
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Contoh Factory pattern
Contoh Factory patternContoh Factory pattern
Contoh Factory pattern
 
Classes2
Classes2Classes2
Classes2
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdf
 
Reflection
ReflectionReflection
Reflection
 
13 inheritance
13   inheritance13   inheritance
13 inheritance
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189
 
Oop
OopOop
Oop
 
08review (1)
08review (1)08review (1)
08review (1)
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.concepts
 
What is design pattern
What is design patternWhat is design pattern
What is design pattern
 
The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196
 
Calc ii complete
Calc ii completeCalc ii complete
Calc ii complete
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 

Dernier

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Dernier (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Learn Spring Framework and Dependency Injection in 40 Steps

  • 1. In this tutorial we will cover spring framework and we will learn how to use spring frame work. What is spring framework: -It’s actually a lot of things put into one.Spring is really popular for dependency injection. Dependency Injection: - this is sometimes called as dependency called as dependency inversion, and definitionis “how you will decouple conventional relationship between objects that are related to each other”i.e. one is dependent on other. The idea is to decouple the dependencies so that they are not tied to each other. I will take an example to explain what it means. Example: - I have a drawing application that draws different shapes like “Circle”, “triangle”, “Square” etc.. 1. I have a circle classit has a“draw ()” method. 2. And I have a triangle class that also has a method “draw ()”. 3. Now I can use these objects circle or a triangleto draw a shape onthe screen. 4. Let’s assume I have an application class. a. I can instantiate circle objects inside this class and I can also instantiate triangle object inside this class. b. So code would be something like this c. Now let’s say I don’t want my application to be tied specifically to these objects and I want to use polymorphism. d. Now the question is how will I use polymorphism here? The whole Idea of using polymorphism is to have some type of interface class or some parent class. The example of using polymorphism is here 1. Let’s say I have a circle object and I have a triangle object both have similar draw method 2. Now I will have a “Shape” interface or a “Shape” parent class that has a draw method. 3. Now I will inherit both “Circle” and “Triangle” class from “Shape” Interface
  • 2. 4. Now In my application class I will write code something like this 5. Here I am calling “shape.draw()”If shape has a triangle it will call draw method from triangle 6. So this is the polymorphism here, we are calling polymorphism, instead of calling method of the objects, I have a handle of parent class and I will call the “draw” method of parent class. The parent could be an abstract class or it could be an interface. 7. I don’t know which object I have when I am calling “shape.draw()” 8. But here I am still tying “circle” and “triangle” objects inside “application” class. 9. So application class always know whether it is a triangle or a circle. 10. So will go one step further and I will use “Method parameter” 11. In this code you can see that somewhere in class we are calling class “new Triangle ()”. 12. Somewhere in the class we have to call “myDrawMethod(shape)“ and pass shape object 13. So we are still tied to class name, we are not free from in it. We will take a step further
  • 3. We will move creation of object outside the class and class will not know the shape its drawing, the class will just have a shape, then we will expectsome other class to provide the shape for us. We want to have shape object instead of triangle object inside the class. We will tell another class/object to add this triangle class to application. 1. We will create a drawing class, this class will have class member variable called shape, it will be member variable of type shape, assume I will have a code like this – 2. I will have a private shape object. 3. And then I will define a setter “public setShape (shape)” and I will take a shape as parameter. 4. Shape can accept anything like “circle”, “triangle”, “square” etc… 5. Whatever shape object is passed it will set the variable Shape (Member variable Shape)inside the class. 6. Now I have a “drawShape” method this will call draw()method of class Shape note that this does doesn’t do initialization. (you don’t see a new Shape here) 7. The drawing is gonna assume that something will instantiate that and will provide that object to this class. 8. Now we have removed the dependency of triangle or a shape, in order to draw a triangle you don’t have to modify the Shape class. All you need to do is pass a shape type(i.e Triangle or circle.. etc.) to setter setShapeand then call drawShapeit will draw the desired shape. Example 9. The whole idea is you don’t have to modify the drawing class. 10. You are separating the dependency out from the class, the drawing class doesn’t really now that on what it is dependent, the advantage is that “if what it has to draw is changes you don’t have to modify the drawing class because it doesn’t really know in first place” 11. You can make drawing class to draw all kinds of shape without modifying the base class. 12. Reason – the dependency ofDrawing class to a shape object is not owned by the Drawing class. The Drawing class doesn’t own the relationship of the actual shape. 13. The dependency of drawing class is injected by the desired shape class. Dependency of Drawing class is not hard coded but it is injected by an external entity. This is all about dependency Injection