SlideShare a Scribd company logo
1 of 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

More Related Content

Similar to 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
 

Similar to 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
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
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
 
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
 
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
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
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...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
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
 
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...
 
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
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 

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