Lightweight Development Strategies

batterycopperInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 3 χρόνια και 4 μήνες)

54 εμφανίσεις

Lightweight Development Strategies

JavaZone, Olso 2005

Bruce A. Tate

http://www.springframework.com

bruce.tate@j2life.com




Agenda


Introduction


Process


POJO programming frameworks


Inversion of control (not just DI)


Conclusion


Progress report


Introduction


Process


POJO programming frameworks


Inversion of control (not just DI)


Conclusion


About Me


Author 6 books


Better, Faster, Lighter Java


Bitter Java, Bitter EJB


Spring Developer Notebook


Beyond Java due this Summer


Independent consultant, author, speaker


Founder and president of J2Life, LLC


Customers include FedEx, Great West Life, IHS, many others


Worked for IBM for 13 years


Database lab


Object infrastructure lab


Java consulting

Motivation


Java development must get


Simpler


More reliable


More efficient









Or it will die!

Java is bloating


Pressure to add


With no counterbalance


Pressure from industry


Big money creates massive frameworks


To solve massive problems


And sells them to the mainstream


Misuse


Massive frameworks for simple problems

How will you respond?


Do nothing


Pick a new language or environment


Pick a new development paradigm


Let your vendor shield you from
complexity


Simplify


The subject of this talk

Progress report


Introduction


Process


POJO programming frameworks


Inversion of control (not just DI)


Conclusion


Which process?


Pick a couple of principles


And follow them


And call it whatever you want to

Emphasis (in order) on


Small, smart teams


Good feedback from customers


Quality


Simple requirements management


Simplicity


Refactoring


Automated unit testing

Agile Development Perception


Managers often fear agile processes


Perception is lack of discipline

Agile
development

(XP, Scrum)

Formal OO
development

(RUP)

Discipline



Design artifacts



Early design



Meticulous requirement



Like, just wing
it, dude!

Agile Development


Agile development is disciplined


It draws discipline from another source

Agile
development

(XP, Scrum)

Formal OO
development

(RUP)

Discipline



Design artifacts



Early design



Meticulous requirement



Automated testing



Continuous integration



Refactoring emphasis



On site customer

Principles: Getting started

Don’t sell a process; sell principles.



Simplicity


Continuous refactoring and integration


Automated tests, code tests first


Small teams with access to customer


Progress report


Introduction


Process


POJO programming frameworks


Inversion of control (not just DI)


Conclusion


POJO programming


Stretching Java!


Adding services


Interceptors


AOP


Proxies


Dependency injection


Loosen coupling


Multiple configurations of components


Concepts: dependency injection


Old ways:


Hard wiring



service = new service()


Limiting: relies on tight coupling


Lookup



Application.register(service, serviceName);








client.lookup(serviceName)



Traditional J2EE way.


Loosens coupling but does not break it


Concepts: dependency injection


The parts: a service, a consumer, and a
container

1.
Wrap the service in an interface

2.
Provide a property in the consumer


Type: the service’s interface

3.
Let the container manage life cycles

4.
The container is responsible for setting
the property in the consumer

Setter
-
based injection example

1.
Load context

2.
Instantiates beans

3.
Configures simple properties

4.
Resolves dependencies

Configuration File


Beans



Name:

MyDataSource


URL:


host/ProductDatabase


UserID:

batate


Password:

pass



Name:

PetStoreDao


Datasource:

MyDataSource


Version:

4.7

MyDataSource





PetStoreDao



URL: host/ProductDatabase

UserID: batate

Password: pass

Version: 4.7

Datasource: MyDataSource

What is AOP?


AOP seeks to get crosscutting concerns


Away from main
-
line code


To develop AOP code


You build your main
-
line logic


You code independent services


And weave them together with configuration


Advantages


Full transparency to services


Isolated aspects (often pre
-
defined)


Disadvantages? Immature

The core problem

Method body









Exceptions





Method Client


Mainline logic

Security

Commit transaction

Open transaction

Roll back

Security

Open transaction

Commit transaction

Roll back

Active strategies


AOP


Code generation


Example: EJB 2.x


Byte code enhancement/injection


Run time: dynamic proxies


Hibernate, Spring, Hive Mind, etc


Compile time: byte code injection step


JDO, AspectJ, obfuscators


Source level metadata


Can be both active and passive


In Java 5 annotations


In XDoclet tags

Passive strategies


Reflection


Deal with an object via its primitive parts


Deal with methods, attributes generically


Combine with other techniques


Example: Hibernate

Java limitations


How do you express configuration:


For dependency injection?


For AOP?


For reflection (specify methods, sigs, etc)


In Java or XML?


Metaprogramming in Java?

Progress report


Introduction


Process


POJO programming frameworks


Inversion of control (not just DI)


Conclusion


Inversion of control


Java’s customization is outside first







while(i<length) {





row =
customLibrary();




}





Certain problems require inside out
customization


Iteration


JDBC

Custom

code

Typical JDBC

Example from jPetStore


Get a list of pet types (Strings)


JdbcTemplate template = new JdbcTemplate(dataSource);

final List names = new LinkedList();

template.query(
"SELECT id,name FROM types ORDER BY name",


new RowCallbackHandler() {


public void processRow(ResultSet rs)


throws SQLException


{


names.add(rs.getString(1));


}


});



What is a continuation?


The rest of the program


A frozen point in time


A copy of the call stack


With local variable values


And current point of execution

Continuation server


Back button


Threading


Inversion of control

Browser

Server

Request

Request

Request

Request

Query

Query

Query

Application

A brief demo


Seaside


Developed by Avi Bryant


In a language called Squeak


A derivative of Smalltalk

Solution in Java


Spring WebFlow


Implement a state machine


Specify a machine using Web Flow rules


Nodes are pages or methods


Transition on events (failure, success, etc)


Store a state in a dictionary like a continuation


Rife


Implements native Java continuations


Watch class loader, get stack


Compute offset to current line of code


Do byte code injection to insert stack


Skip to current line of code


Force all instance variables to implement Clonable


Cocoon 2


Implement Java on Rhino (JavaScript engines)


Use custom code to implement continuations in Rhino

Language limitations


Java needs code blocks!


Closures are important parts of other
languages


They are more useful with dynamic typing


Continuations are important

Progress Report


Introduction


Philosophies


Process


Technologies


Conclusion

Predictions


Spring replaces EJB


EJB will struggle


Again


They’re late


Both annotations and AOP will get us into
trouble, in spots


Java meta
-
programming increases


Moving more people to dynamic languages


REST will slowly subsume WebServices


Except maybe SOAP


One dynamic language explodes (Ruby?)

Resources


Quick starts and philosophy books


Better, Faster, Lighter Java by Tate, Gehtland


Spring Developer Notebook by Tate, Gehtland


Make sure you get the reprint


Hibernate Developer Notebook by Elliot


References


Pro Spring


Hibernate in Action


REST tutorial:
http://www.xfront.com/REST.html


Spring: Good article
http://www.sys
-
con.com/story/print.cfm?storyid=47735



Lightweight development series on DeveloperWorks