Java EE - Dependency Injection -

Slides:



Advertisements
Similar presentations
Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
Advertisements

Spring, Hibernate and Web Services 13 th September 2014.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Plab – Tirgul 12 Design Patterns
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
7/16/2015Singleton creational design pattern1 Eivind J. Nordby Karlstad University Dept. of Computer Science.
1 November 21st 2009 Shaun Abram An Introduction to Spring.
The Spring Framework: A brief introduction to Inversion of Control James Brundege
 Proteus Framework Redefining the plugin. Why a new framework?  Present approaches (e.g. OSGi) use non-standard approaches that create too many breaking.
Design Patterns.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
CPSC 410.  Build on previous Connector lectures  Learn how to implement flexible connector implementations  Learn the Dependency Injection pattern.
Copyright (C) 2009 by Abdelmonaim Remani. All rights reserved. By Abdelmonaim Remani Polymathic-coder.com Silicon Valley Code.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Abstract Factory Design Pattern making abstract things.
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
DEPENDENCY INJECTION & INVERSION OF CONTROL. WHAT’S GOING TO BE COVERED Quick intro to C# for Java developers Dependency Injection Inversion of Control.
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework,
Dependency Injection Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 ©
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Alternative Architectures: Inversion of Control Mike Hadlow mikehadlow.blogspot.com.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Creational Patterns
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
Introducing Allors Applications, Tools & Platform.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Professional Java EE Design Patterns Alex alextheedom.com.
Design of an Integrated Robot Simulator for Learning Applications Brendon Wilson April 15th, 1999.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
Dependency Injection Frameworks Technion – Institute of Technology Author: Assaf Israel - Technion 2013 ©
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks
SCA and Java n SCA provides support for multiple Java-based component implementation types l Java POJOs (implementation.java) l Spring Beans (implementation.spring)
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
Dependency Inversion By Steve Faurie. Dependency Inversion Described in Agile Principles, Patterns and Practices in C# by Robert C. Martin.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Dependency Injection with Guice Technion – Institute of Technology Author: Gal Lalouche - Technion 2016 ©
Introduction to Inversion Of Control (IOC). IOC Definition (based on Wikipedia)  Consider the way in which an object obtains references to its dependencies.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
CS520 Web Programming Spring – Inversion of Control Chengyu Sun California State University, Los Angeles.
Generator Design Patterns: Singleton and Prototype
J2EE Lecture 6: Spring – IoC and Dependency Injection
Architecture Patterns Design Patterns
Unit II-Chapter No. : 5- design Patterns
Week 2, Day 1: The Factory Method Pattern
CS520 Web Programming Spring – Inversion of Control
How to be a Good Developer
PRG 421 Education for Service-- snaptutorial.com.
PRG 421 Education for Service-- snaptutorial.com.
PRG 421Competitive Success/tutorialrank.com
Advanced Programming Behnam Hatami Fall 2017.
Abstract Factory Pattern
Design Patterns in Game Design
Present by Andie Saizan, MCP
Tuesday Brown Bag Inversion of Control with Howard Abrams
Leveraging ColdSpring To Make Better Applications
Designing For Testability
Dependency Inversion principle
Presentation transcript:

Java EE - Dependency Injection - Pierre-Johan CHARTRE pierre-johan.chartre@logica.com

Coupling vs dependency “In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.” http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29 Hight coupling (concrete): your dependency is an instance of a concrete class. private ArrayList<String> myList; Low coupling (abstract/interface): your dependency is an instance of an abstract class. private List<String> myList; Limitations: Component replacing, refactoring Test writing, mock Component overriding

Example: A hight coupling app MyScreen <<Servlet>> MyService <<Object>> MyDAO <<Object>> MyObject <<Object>> uses uses uses uses OracleDriver <<jar>>

How to remove coupling ? A solution based on Design Patterns Creation design patterns Factory Singleton Structural design patterns Proxy Architectural design pattern Inversion of Control & Dependency Injection

How to remove coupling ? Using the Factory Design Pattern ?

How to remove coupling ? Service Provider Interface (SPI) the Java 3 approach Define implementations in a text file META-INF/services/com.isima.spi.IDAO com.isima.MyTestDAO com.isima.MyDAOOracle Get implementations ServiceLoader loader = ServiceLoader.load(com.isima.spi.IDAO.class); Iterator iterator = loader.iterator(); while (iterator.hasNext()) { IDAO dao = (IDAO) iterator.next(); dao.find(); } Limitation: static injection IDAO <<Object>> MyTestDAO <<Object>> MyDAOOracle <<Object>>

Dependency Injection « OK, we removed coupling, but it will be better if it’s dynamic ! » It’s « Inversion of Control » (IoC)

Dependency Injection « OK, but we could introduce more features ! » Singleton for only one instance Multiple implementation for the same interface Default implementation AOP Mock for unit tests Annotation support …

Example: A low coupling app MyScreen <<Servlet>> IService <<Object>> IDAO <<Object>> MyObject <<Object>> uses uses uses MyTestService <<Object>> MyService <<Object>> uses MyTestDAO <<Object>> MyDAOOracle <<Object>> OracleDriver <<jar>> 3 Configurations 1 for screen testing 1 for service testing 1 for DAO testing

J2EE is a standard ! JSR 330: Dependency Injection for Java @Inject @InMyServlet private IService service; A J2EE is one JSR, multiple implementations WELD OpenWebBeans Google Guice Spring …