Week 7 Spring Rest Study Flashcards
What are Spring Projects
Spring Projects are a collection of projects that complement and extend the Spring Framework.
What is the Spring Framework?
The Spring Framework is a Java platform that provides infrastructure support for developing java applications so that the developer can focus more on the business logic part of the application.
What is the Spring Framework
The Spring Framework is a lightweight solution for building enterprise-level applications that supports business logic.
What are some features of the Spring Framework
1.) It is modular, allowing you to use only the modules from the framework that you need for your application without depending on the whole framework.
2.) All Spring Modules share the same release version as the Framework. They are also a part of the same project.
What is the main idea of the Spring Framework?
The Spring Framework includes an Inversion of Control (IoC) container that manages the Java objects
(the zookeeper of the application’s “ecosystem” that conducts these spring modules and the rest of our application to function harmoniously together).
What is IoC and what does the IoC container do?
Inversion of Control, or IoC, is a principle in software engineering by which the control of objects or portions of a program is transferred to a container or framework. The main goal of Spring’s IoC container is a separation of concerns. It decouples the execution of a task from its implementation.
What is the IoC container responsible for?
The IoC container is responsible for instantiating, configuring, and assembling the beans of the application.
The container gets its instructions on what / how?
The container gets its instruction on what objects to instantiate, configure, and assemble.
It does this by reading configuration metadata stored in the XML/YML/properties file.
What are some advantages of IoC?
Decoupling of the program from the infrastructure.
Making it easier to switch between different implementations.
Greater modularity of a program.
Greater eas in testing a program by isolating a component or mocking its dependencies and allowing components to communicate through contracts.
What is dependency injection?
Dependency injection is a specific style of IoC.
DI = more specific IoC
IoC = a generic pattern of control flow between app implementation.
Dependency Injection: implementations are passed into an object through constructors, setters, service lookups, which the object will ‘depend’ on in order to behave correctly.
What are some benefits of Dependency Implementation?
Reduced dependencies, and reduced dependency carrying.
Reduced dependencies reduces the vulnerability of an object from changes that might occur from a dependency changing.
Reduced dependency carrying is when an object takes a parameter in one of its methods that it doesn’t need itself, but is needed by one of the objects it calls to carry out its work. This can make it harder to maintain or test code.
More reusable code
More testable code = DI makes it possible to inject mock implementations of dependencies.
More readable code
What types of dependency injection does Spring support?
Constructor Injection: Dependency Injection accomplished when the container invokes a constructor with arguments to instantiate a bean in which each argument of said constructor represents a dependency.
Setter Injection: Dependency Injection accomplished when the container calls a setter methods on a bean after invoking a no-argument constructor to instantiate a bean.
What are the differences between Constructor injection and Setter injection?
Constructor injection is more secure since dependencies are required to create an object, you are guaranteed to have each dependency populated. It also enables the implementation of immutable objects.
Setter injections allow for partial dependencies since Constructor injection requires all properties to be established upon bean instantiation.
Setter injections can easily change values, and does not create new bean instances making it more flexible than constructor injection.
Setter injection can resolve circular references. ( i.e. If object A and object B are dependent on each other, a setter injection can be used to resolve this, whereas a constructor injection would throw a BeanCurrentlyInCreationException).
What is a Field Injection?
A field injection is a type of injection that is possible only in the annotation based approach due to the fact that it is not really a new injection type - under the hood spring uses reflection to set these values.
What are some advantages of Field Injections?
It is easy to use as no constructors or setters are required.
It can be easily combined with the constructor and/or setter approach