Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 2006, Codeguild, Inc Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc.

Similar presentations


Presentation on theme: "Copyright 2006, Codeguild, Inc Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc."— Presentation transcript:

1 Copyright 2006, Codeguild, Inc Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc. http://codeguild.com/

2 Copyright 2006, Codeguild, Inc 2 Framework Defined A framework provides tools, designs, templates, and practices to somehow make development easier Java frameworks tend to divide into front-end (display), middle (control logic), and/or back-end (persistance) functions

3 Copyright 2006, Codeguild, Inc 3 Java Frameworks (parial list) Struts (2001) Avalon (1999) Cocoon (1999) Expresso (2000) Webwork JavaServer Faces (2004)/Shale Seam (2005) Spring (2002) Tapestry Struts Action Framework (from Webwork) 2005 Hibernate

4 Copyright 2006, Codeguild, Inc 4 Outline Two criteria for judging a framework –Loose coupling/Inversion of Control (IoC)/Dependency injection –Aspect-oriented programming (AOP) Choosing a framework

5 Copyright 2006, Codeguild, Inc 5 Why is IoC important? Integrate with other frameworks, other services –plug in a persistence layer, a display layer, etc. Extensive unit-test coverage of framework code –the less dependence between classes, the easier to test

6 Copyright 2006, Codeguild, Inc 6 Interface vs. Concrete Interface is a specification of signatures—no implementation Concrete class has implementation of every method; can be instantiated –(Abstract class is in between— some, but not all, methods implemented)

7 Copyright 2006, Codeguild, Inc 7 Tight Coupling class Foo { void bar() { FastStringBuffer aBuffer = FastStringBuffer. getInstance(); //... }

8 Copyright 2006, Codeguild, Inc 8 Loose Coupling StringBufferFactoryInterface aBuffFac = getStringBuffer(); ------------------------------------ public StringBufferFactoryInterface getStringBuffer() { /* ??? how implement with no dependence ??? */ }

9 Copyright 2006, Codeguild, Inc 9 Loose Coupling (IoC) StringBufferFactoryInterface aBuffFac = getStringBuffer(); ----------------------------------------- public StringBufferFactoryInterface getStringBuffer() { return stringBufferFac; } public void setStringBuffer( StringBufferFactoryInterface aBuff) { stringBufferFac = aBuff; } private StringBufferFactoryInterface stringBufferFac;

10 Copyright 2006, Codeguild, Inc 10 Spring configuration, injecting dependencies <bean id=“fastStringBuffer” class=“FastStringBuffer” />

11 Copyright 2006, Codeguild, Inc 11 Spring is an IoC Bean Factory InputStream is = new FileInputStream("src/examples/ spring/beans.xml"); BeanFactory factory = new XmlBeanFactory(is); DataProcessor dataProcessor = (DataProcessor) factory.getBean("fileDataProce ssor"); Result result = dataProcessor.processData();

12 Copyright 2006, Codeguild, Inc 12 Aspect-Oriented Programming (AOP) Rationale Object oriented programming (OOP) isn’t good at everything. Consider: – Security: want to test privileges every time method is invoked. –DB transactions: want to have every access to DB run through transaction

13 Copyright 2006, Codeguild, Inc 13 Transaction OO example DBConnection conn = DBConnectionPool.getInstance().getConnection("course clone"); try { conn.setAutoCommit(false); Course clonecourse = new Course(conn);... } catch (Exception e) { conn.rollback(); getLogger().error(e); } finally { conn.release(); }

14 Copyright 2006, Codeguild, Inc 14 AOP Transactions, Logging and Security are often referred to as “crosscutting” concerns, applying to all objects For every method, AOP inserts ‘advice’ before and/or after method call Spring uses dynamic AOP, creating “proxies” for all advised objects

15 Copyright 2006, Codeguild, Inc 15 AOP Example in Spring Using JDK1.5 annotations! @Transactional public void saveCourse( Course src) { getCourseDBO().save(src); }

16 Copyright 2006, Codeguild, Inc 16 Choosing the Right Tool If you already know tool ++ Currently popular tool ++ Estimate lifespan of project Estimate audience (users) Estimate need to interface with external resources (email, LDAP) Impartial, comprehensive reviews are hard to find Any framework will go obsolete!

17 Copyright 2006, Codeguild, Inc 17 Opinion Is two-tier PHP good enough? Bigger projects: take care not to overestimate—”You’re not going to need it” Watch: –Ruby on Rails (David Hansson) –Seam (Gavin King) –Spring (Rod Johnson)

18 Copyright 2006, Codeguild, Inc 18 http://codeguild.com/presentations/


Download ppt "Copyright 2006, Codeguild, Inc Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc."

Similar presentations


Ads by Google