Thursday 22 March 2018

1. Service locator design pattern


Service Locator design pattern.

1.     The service locator design pattern is used when we want to locate various services using JNDI lookup.
2.     Service Locator uses catching technique internally.
3.     For first time a service is required, Service locator lookups in JNDI and caches the service object.
4.     Further lookup for same service it picks from cache, so it improves performance of application.
5.     Following entities
a.     Service – Object, we are looking for
b.     Context – JNDI context save ref of service for lookup
c.     Service Locator – Get services by JNDI lookup catching the services
d.     Cache – To store the ref of services to reuse.
e.     Client – client invokes service ref via Service Locator







3. Introduction to Spring container

Introduction to Spring container
1.     IoC – Inversion of Control is also known as Dependent Injection.
2.     IoC is a process where objects define their dependencies through
a.     Constructor arguments – Constructor Injection
b.     Arguments to a factory method – Method Injection
c.      Properties to setter methods – Setter Injection
d.     Interface Injection
e.     Lookup method Injection
3.     The IoC container injects those dependencies when it creates bean.
4.     This process is fundamentally called as Inverse, hence the name is Inversion of Control.
5.     Spring container itself controlling the instantiation and location of its dependencies by using direct constructor classes or a mechanism such as Service Locator pattern.
6.     Basic spring packages for containers
a.     org.springframework.beans.*
b.     org.springframework.context.*
7.     Basic Spring IoC containers are
a.     org.springframework.beans.factory.BeanFactory (Interface)
b.     org.springframework.beans.factory.ApplicationContext (Interface)
8.     The objects that are formed/created and managed by spring container are called as Spring beans.
9.     BeanFactory  vs ApplicationContext
BeanFactory
ApplicationContext
1. Root interface for accessing spring bean container.
1. Child interface of BeanFactory interface
2. It provides configuration framework .
2. It provides more enterprise specific functionality.
3. It provides basic functionality.
3. It adds integration with AOP features, message resource handling (I18N), event publications.
4. Some Implementation classes are
1.     XmlBeanFactory
2.     DefaultListableBeanFactory
3.     SimpleJndiBeanFactory
4.     StaticListableBeanFactory
4. Implementation classes are
1.     XmlApplicationContext
2.     FileSystemXmlApplicationContext
3.     ClassPathXmlApplicationContext
4.     AnnotationConfigWebApplicationContext



3. Java Program to create Binary Tree