Spring 101 Struts University Series. About Ted Husted Lead author, Struts in Action Co-Author, JUnit in Action Member, Apache Software Foundation Member,

Slides:



Advertisements
Similar presentations
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Advertisements

Spring, Hibernate and Web Services 13 th September 2014.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Lecture 9 Concepts of Programming Languages
ASP.NET Programming with C# and SQL Server First Edition
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
1 November 21st 2009 Shaun Abram An Introduction to Spring.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Review of C++ Programming Part II Sheng-Fang Huang.
CVSQL 2 The Design. System Overview System Components CVSQL Server –Three network interfaces –Modular data source provider framework –Decoupled SQL parsing.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
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.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Understanding the Bean Lifecycle An.
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.
PicoContainer Presented by: Jim O’Hara Ed Kausmeyer Jingming Zhang.
Anti Orgla, Nortal AS Spring Framework
Copyright © 2005 Finetix LLC All Rights Reserved 0 SpringFramework.Net Developer Session Chris Donnan The Peer Frameworks Series -.Net and Java.
Objects First With Java A Practical Introduction Using BlueJ Designing applications 1.0.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Spring Training 17/09/ Dependency Injection.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework,
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Dependency Injection Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 ©
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical.
C arrays are limited: -they are represented by pointers (which may or may not be valid); -Indexes not checked (which means you can overrun your array);
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
KEW Definitions Document Type The Document Type defines the routing definition and other properties for a set of documents. Each document is an instance.
Reusing Code in C++ Has-a relationship Classes with member objects(containment) The valarray template class Private & protected inheritance Multiple inheritance.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Professional Java EE Design Patterns Alex alextheedom.com.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Dependency Injection Frameworks Technion – Institute of Technology Author: Assaf Israel - Technion 2013 ©
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
.NET Mobile Application Development XML Web Services.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
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.
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns © 2017 Pearson Education, Inc. Hoboken,
Developing Custom ASP.NET Providers For Membership And Role Manager Stefan Schackow PRS404 Program Manager – Web Platform and Tools Microsoft Corporation.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
CS520 Web Programming Spring – Inversion of Control Chengyu Sun California State University, Los Angeles.
J2EE Lecture 6: Spring – IoC and Dependency Injection
MPCS – Advanced java Programming
CS520 Web Programming Spring – Inversion of Control
Creational Pattern: Prototype
Intent (Thanks to Jim Fawcett for the slides)
Lecture Set 10 Windows Controls and Forms
CS 350 – Software Design Singleton – Chapter 21
Chapter 8: Class Relationships
Dependency Injection in .Net Core
Instructor: Dr. Michael Geiger Spring 2019 Lecture 23: Exam 2 Preview
MS Confidential : SharePoint 2010 Developer Workshop (Beta1)
Presentation transcript:

Spring 101 Struts University Series

About Ted Husted Lead author, Struts in Action Co-Author, JUnit in Action Member, Apache Software Foundation Member, Struts PMC and iBATIS PMC Working developer

Refactoring with Spring Inside Spring

How can we use Spring to simplify development? Working example without Spring Refactor to use Spring

Client story Manage simple types We want to edit the descriptions of items that appear in our drop-down lists. We want to add new items to the drop-down lists.

Client conversation Lists are drawn from simple data tables Seven lists Two to five columns Three to 70+ items Doesn't want to delete (right now) Could use a datagrid with in-place editing Must be idiot-proof (e.g. validate input)

Development issues Different queries for different tables Different validations for different columns Some columns can be blank, some cannot Most columns are strings, but some are integers or dates

Things to Avoid Seven controls for seven tables

Likely solution Dynamic datagrid Helper classes

Class management One interface One base class Seven instant classes

Datagrid markup

Code-behind public interface ITypesHelper : IViewHelper { string EditText { get; set; } string QuitText { get; set; } string SaveText { get; set; } string ListCommand { get; set; } string SaveCommand { get; set; } string DataKeyField { get; set; } IList DataFields { get; set; } IList DataLabels { get; set; } int BindColumns (DataGrid grid, int i); void DataSource (DataGrid grid); void DataBind (DataGrid grid); void Save (string key, ControlCollection controls) ; }

BindColumns method public virtual int BindColumns (DataGrid grid, int i) { grid.DataKeyField = DataKeyField; i = BindEditColumn (grid, i); int colCount = DataFields.Count; int lblCount = DataLabels.Count; for (int c = 0; c < colCount; c++) { string column = DataFields [c] as string; string label = (lblCount < c) ? column : DataLabels [c] as string; i = View.BindColumn (grid, i, label, column) ; } return i; }

TypesHelper instance private class CountyHelper : TypesHelper { public CountyHelper () { ListCommand = "County.List"; SaveCommand = "County.Save"; DataKeyField = "CountyKey"; IList dataFields = new ArrayList (2); dataFields.Add ("CountyName"); dataFields.Add ("EclsOffice"); DataFields = dataFields; IList dataLabels = new ArrayList (2); dataLabels.Add ("County Name"); dataLabels.Add ("ECLS Office"); DataLabels = dataLabels;} }

Code-behind private const string cmd_County = "County"; private const string cmd_Event = "Event"; private const string cmd_Program = "Program"; private const string cmd_Status = "Status"; private const string cmd_Staff = "Staff"; private const string cmd_Ticket = "Ticket"; private void Select_Init_Types (ListItemCollection items) { items.Add (cmd_County); items.Add (cmd_Event); items.Add (cmd_Program); items.Add (cmd_Staff); items.Add (cmd_Status); items.Add (cmd_Ticket); }

Code-behind private ITypesHelper dgList_Helper_Init (string category) { dgList_Helper = null; switch (category) { case cmd_County: dgList_Helper = new CountyHelper (); break; //... case cmd_Ticket: dgList_Helper = new TicketHelper (); break; default: throw new NotImplementedException (); } return dgList_Helper; }

TypesHelper instance private class CountyHelper : TypesHelper { public CountyHelper () { ListCommand = "County.List"; SaveCommand = "County.Save"; DataKeyField = "CountyKey"; IList dataFields = new ArrayList (2); dataFields.Add ("CountyName"); dataFields.Add ("EclsOffice"); DataFields = dataFields; IList dataLabels = new ArrayList (2); dataLabels.Add ("County Name"); dataLabels.Add ("ECLS Office"); DataLabels = dataLabels;} }

CountyTypesHelper County.List County.Save CountyKey CountyName EclsOffice County Name ECLS Office

Code-behind private const string cmd_County = "County"; private const string cmd_Event = "Event"; private const string cmd_Program = "Program"; private const string cmd_Status = "Status"; private const string cmd_Staff = "Staff"; private const string cmd_Ticket = "Ticket"; private void Select_Init_Types (ListItemCollection items) { items.Add (cmd_County); items.Add (cmd_Event); items.Add (cmd_Program); items.Add (cmd_Staff); items.Add (cmd_Status); items.Add (cmd_Ticket); }

TypesSelectItem County CountyTypesHelper

Code-behind private ITypesHelper dgList_Helper_Init (string category) { dgList_Helper = null; switch (category) { case cmd_County: dgList_Helper = new CountyHelper (); break; //... case cmd_Ticket: dgList_Helper = new TicketHelper (); break; default: throw new NotImplementedException (); } return dgList_Helper; }

Factory.GetObject private ITypesHelper dgList_Helper_Init (string category) { dgList_Helper = Factory.GetObject(category) as ITypesHelper; if (dgList_Helper==null) throw new NotImplementedException (); return dgList_Helper; }

CountyTypesHelper County.List County.Save CountyKey CountyName EclsOffice County Name ECLS Office

TypesSelectItem County CountyTypesHelper

Factory.GetObject private ITypesHelper dgList_Helper_Init (string category) { dgList_Helper = Factory.GetObject(category) as ITypesHelper; if (dgList_Helper==null) throw new NotImplementedException (); return dgList_Helper; }

Spring Spring is a generic object factory Replaces programmatic singletons Replaces service locator stubs Spring provides a smart object repository Most often configured via XML documents Each object has a logical ID (not a classname) Resolves dependencies between objects

TypesSelectItem County CountyTypesHelper

Spring Spring decouples specific datatype dependency from program logic Encourages interface-driven development Encourages reuse of shared objects Centralizes configuration of shared and custom logic

Dependency Injection Spring objects define dependencies by a constructor, a factory method, or properties. The Spring container injects dependencies when it creates the object

Inversion of Control Constructor Object appear without dependencies Coupled to type Dependency controlled by caller Container Objects appear with dependencies Coupled to interface Dependency controlled by container

Inversion of Control Container the inverse of using new operator or Service Locator pattern Hence: Inversion of Control

IOC 123 Types of IoC: Type 1 – Interface Injection (Avalon) Type 2 – Constructor Dependency Injection Type 3 – Setter Dependency Injection "The question is: What aspect of control are we inverting?".

Spring Lifecycle Container instantiated Configuration validated Singletons created, properties set Object dependencies set by properties or constructor arguments. Dependencies provided when object is created

Spring Lifecycle Each dependency (property or constructor argument) is a value, or a reference to a container-managed object Values must convert to target datatype Spring will convert strings to any built-in type: int, long, string, bool, et al. Values may define IList, IDictionary, KeyValue, and Set collection types.

IObjectFactory Instantiates, configures, and manages a set of objects. Managed objects typically collaborate Dependencies between themselves Collaborator dependencies evident in configuration

IApplicationContext Extends IObjectFactory Application-centric features Localization using resource files Event-propagation Resource-loading

Bootstrapping IApplicationContext factory = ConfigurationSettings.GetConfig("s pring/context") as IApplicationContext;

.NET standard configuration <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" <context type="Spring.Context.Support.XmlApplicationContext, Spring.Core">

spring/objects.xml ?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE objects PUBLIC "-//SPRING//DTD OBJECT//EN" "

Object Definitions Object definitions describe Objects managed by an IObjectFactory or IApplicationContext.

Object Definitions Object definitions contain: Object type Container modes prototype or singleton autowiring dependency checkin initialization and destruction methods Values to set in the newly created object. Collaborators (aka dependencies)

"Dependency is the leading problem in software development at all levels." -- Kent Beck

Struts University Series