Title: Lightweight Development Strategies JavaZone, Olso 2005
1Lightweight Development StrategiesJavaZone, Olso
2005
- Bruce A. Tate
- http//www.springframework.com
- bruce.tate_at_j2life.com
2Agenda
- Introduction
- Process
- POJO programming frameworks
- Inversion of control (not just DI)
- Conclusion
3Progress report
- Introduction
- Process
- POJO programming frameworks
- Inversion of control (not just DI)
- Conclusion
4About 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
5Motivation
- Java development must get
- Simpler
- More reliable
- More efficient
-
- Or it will die!
6Java 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
7How 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
8Progress report
- Introduction
- Process
- POJO programming frameworks
- Inversion of control (not just DI)
- Conclusion
9Which process?
- Pick a couple of principles
- And follow them
- And call it whatever you want to
10Emphasis (in order) on
- Small, smart teams
- Good feedback from customers
- Quality
- Simple requirements management
- Simplicity
- Refactoring
- Automated unit testing
11Agile Development Perception
- Managers often fear agile processes
- Perception is lack of discipline
Agile development (XP, Scrum)
Formal OO development (RUP)
- Like, just wing it, dude!
- Design artifacts
- Early design
- Meticulous requirement
Discipline
12Agile Development
- Agile development is disciplined
- It draws discipline from another source
Agile development (XP, Scrum)
Formal OO development (RUP)
- Automated testing
- Continuous integration
- Refactoring emphasis
- On site customer
- Design artifacts
- Early design
- Meticulous requirement
Discipline
13Principles Getting started
- Dont sell a process sell principles.
- Simplicity
- Continuous refactoring and integration
- Automated tests, code tests first
- Small teams with access to customer
14Progress report
- Introduction
- Process
- POJO programming frameworks
- Inversion of control (not just DI)
- Conclusion
15POJO programming
- Stretching Java!
- Adding services
- Interceptors
- AOP
- Proxies
- Dependency injection
- Loosen coupling
- Multiple configurations of components
16Concepts 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
17Concepts dependency injection
- The parts a service, a consumer, and a container
- Wrap the service in an interface
- Provide a property in the consumer
- Type the services interface
- Let the container manage life cycles
- The container is responsible for setting the
property in the consumer
18Setter-based injection example
- Load context
- Instantiates beans
- Configures simple properties
- Resolves dependencies
MyDataSource
Configuration File Beans Name
MyDataSource URL host/ProductDatabase
UserID batate Password pass
Name PetStoreDao Datasource
MyDataSource Version 4.7
URL host/ProductDatabase UserID
batate Password pass
PetStoreDao
Version 4.7
Datasource MyDataSource
19What 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
20The core problem
Method body Exceptions
Security
Security
Open transaction
Open transaction
Mainline logic
Method Client
Commit transaction
Roll back
Commit transaction
Roll back
21Active 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
22Passive strategies
- Reflection
- Deal with an object via its primitive parts
- Deal with methods, attributes generically
- Combine with other techniques
- Example Hibernate
23Java limitations
- How do you express configuration
- For dependency injection?
- For AOP?
- For reflection (specify methods, sigs, etc)
- In Java or XML?
- Metaprogramming in Java?
24Progress report
- Introduction
- Process
- POJO programming frameworks
- Inversion of control (not just DI)
- Conclusion
25Inversion of control
- Javas customization is outside first
-
- while(iltlength)
- row customLibrary()
-
- Certain problems require inside out customization
- Iteration
- JDBC
Custom code
26Typical JDBC
27Example from jPetStore
- Get a list of pet types (Strings)
- JdbcTemplate template new JdbcTemplate(dataSourc
e) - 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)) -
- )
28What 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
29Continuation server
- Back button
- Threading
- Inversion of control
Server
Application
Request
Request
Request
Request
Query
Query
Query
Browser
30A brief demo
- Seaside
- Developed by Avi Bryant
- In a language called Squeak
- A derivative of Smalltalk
31Solution 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
32Language limitations
- Java needs code blocks!
- Closures are important parts of other languages
- They are more useful with dynamic typing
- Continuations are important
33Progress Report
- Introduction
- Philosophies
- Process
- Technologies
- Conclusion
34Predictions
- Spring replaces EJB
- EJB will struggle
- Again
- Theyre 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?)
35Resources
- 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?storyid47735 - Lightweight development series on DeveloperWorks