Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Magic Box project:
   Effective K.I.S.S. with SpringFramework




                                          http://sourcef...
The event that host this presentation: Javaday


 Organizzato direttamente dalla collaborazione
 della community Java, gir...
Requirements for this talk


                                        “We believe not only that J2EE development should be
...
Speaker

      Java Architect             *




      Co-fondatore e consigliere

      JugSardegna Onlus                 ...
Spring Knowledge


  Spring User da Luglio
  2004 (Spring 1.1)

  Primo articolo italiano
  settembre 2004 sul
  JugSardeg...
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007...
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007...
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007...
Ideas behind the presentation




                                                                        http://c2.com/cg...
Ideas behind the presentation




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma...
This is not simple




 Don’t worry:
 knowing
 the language
 doesn’t really help.



Massimiliano Dessì - desmax74@yahoo.i...
Simplicity vs Complexity


       I actually enjoy complexity that's empowering. If it
       challenges me, the complexit...
Simplicity



                                                               !=
                     Simplicity           ...
Do the simplest thing



        The most important rule in our development is always to
       do the simplest thing that...
XP View




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
        ...
Do the simplest thing that could possibly work !




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User...
Design




                     Nella pianificazione, mai una mossa inutile;
                     nella strategia, nessun ...
Interface in MagicBox


 EJ Item 16: Prefer interfaces to abstract classes

                                              ...
Interface Advantage


                                  Switch from one implementation ,
                                 ...
Composition


  EJ Item 14: Favor composition over inheritance

              This design is called composition because th...
Composition in Domain Objects


     public final class UtenteImpl implements UtenteView{

           public UtenteImpl ()...
Abstractions from a hierarchy



        Inheritance on interfaces

                     public interface UtenteView exten...
Immutability


   Item 13: Favor immutability


   An immutable class is simply a class whose instances cannot be
   modif...
Immutability


 Only accessors on public interfaces.                                           public interface UtenteUltr...
Data mapper


   The Data Mapper is a layer of software that separates the in-
   memory objects from the database. Its re...
iBATIS mapping class - table

      <typeAlias type=quot;org.magicbox.domain.AmministratoreImplquot; alias=quot;adminquot;...
iBATIS Dao

         public class AmministratoriDaoImpl extends SqlMapClientDaoSupport implements AmministratoriDao{


   ...
Transaction on service layer


 public class AmministratoriManagerImpl implements AmministratoriManager{

 public long sav...
Test !




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
         ...
Demo



       MagicBox it' s a JEE solution to coordinate blood donations




Massimiliano Dessì - desmax74@yahoo.it – Sp...
Q&A



                                                                                             All this leads to
    ...
Thanks for your attention




                                          Massimiliano Dessì
                               ...
Upcoming SlideShare
Loading in …5
×

Javaday Roma2007 Magic Box Kiss With Spring

2,125 views

Published on

Presentation at Javaday 2007 in Rome, about K.i.s.s. principle with SpringFramework in the Project MagicBox

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Javaday Roma2007 Magic Box Kiss With Spring

  1. 1. Magic Box project: Effective K.I.S.S. with SpringFramework http://sourceforge.net/projects/magic-box Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  2. 2. The event that host this presentation: Javaday Organizzato direttamente dalla collaborazione della community Java, gira l'Italia con passione 2007 Javaday è un evento unico nel mondo! 2006 L' edizione romana è a cura di Jug Roma Java Italian Portal Java Italian Association Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  3. 3. Requirements for this talk “We believe not only that J2EE development should be much simpler than the mixture of drudgery and complexity it’s often made out to be, but that developing J2EE applications should be fun” Rod Johnson http://www.springframework.org/ Ralph, Erich, Richard, John at OOPSLA 1994 http://c2.com/cgi/wiki?GangOfFour http://c2.com/cgi/wiki?DesignPatternsBook Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  4. 4. Speaker Java Architect * Co-fondatore e consigliere JugSardegna Onlus 2003 * plus others bla bla bla bla Fondatore e coordinatore: SpringFramework Italian User Group 2006 Jetspeed Italian User Group 2003 Groovy Italian User Group 2007 Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  5. 5. Spring Knowledge Spring User da Luglio 2004 (Spring 1.1) Primo articolo italiano settembre 2004 sul JugSardegna. Primo corso di formazione su Spring in Italia maggio 2005 per la Sistemi Informativi a Roma. Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  6. 6. MagicBox Project Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  7. 7. MagicBox Project Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  8. 8. MagicBox Project Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  9. 9. Ideas behind the presentation http://c2.com/cgi/wiki?SevenPrinciplesOfSoftwareDevelopment Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  10. 10. Ideas behind the presentation Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  11. 11. This is not simple Don’t worry: knowing the language doesn’t really help. Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  12. 12. Simplicity vs Complexity I actually enjoy complexity that's empowering. If it challenges me, the complexity is very pleasant. But sometimes I must deal with complexity that's disempowering. The effort I invest to understand that complexity is tedious work. It doesn't add anything to my abilities. What's the Simplest Thing that Could Possibly Work ? Simplicity: the Shortest Path to a Solution Ward Cunningham http://www.artima.com/intv/simplest.html Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group http://c2.com/cgi/wiki?WardCunningham Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  13. 13. Simplicity != Simplicity Quick and Dirty Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  14. 14. Do the simplest thing The most important rule in our development is always to do the simplest thing that could possibly work. Not the most stupid thing, not something that clearly can’t work. But simplicity is the most important contributor to the ability to make rapid progress. Ronald E.Jeffries http://www.xprogramming.com/Practices/PracSimplest.html Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  15. 15. XP View Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  16. 16. Do the simplest thing that could possibly work ! Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  17. 17. Design Nella pianificazione, mai una mossa inutile; nella strategia, nessun passo compiuto invano. Sun Tzu The art of war Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  18. 18. Interface in MagicBox EJ Item 16: Prefer interfaces to abstract classes For all Objects Domain Services Dao Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  19. 19. Interface Advantage Switch from one implementation , List entries = new java.util.ArrayList(); Map map = new java.util.HashMap(); to another more aggressive List entries = new javolution.util.FastList(); Map map = new javolution.util.FastHashMap(); Felino micio = new Gatto(); without affecting the client Felino micio = new TigerInsideImpl(); Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  20. 20. Composition EJ Item 14: Favor composition over inheritance This design is called composition because the existing class becomes a component of the new one. Each instance method in the new class invokes the corresponding method on the contained instance of the existing class and returns the results. This is known as forwarding, and the methods in the new class are known as forwarding methods. Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  21. 21. Composition in Domain Objects public final class UtenteImpl implements UtenteView{ public UtenteImpl (){ utenteLight = new UtenteLightImpl(); indirizzo = new IndirizzoImpl(); recapiti = new RecapitoTelefonicoImpl(); } ... Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  22. 22. Abstractions from a hierarchy Inheritance on interfaces public interface UtenteView extends UtenteLightView{ ... } public interface UtenteLightView extends UtenteUltraLightView{ ... } public interface UtenteUltraLightView { ... } Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  23. 23. Immutability Item 13: Favor immutability An immutable class is simply a class whose instances cannot be modified. All of the information contained in each instance is provided when it is created and is fixed for the lifetime of the object. Immutable classes are easier to design, implement, and use than mutable classes. They are less prone to error and are more secure Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  24. 24. Immutability Only accessors on public interfaces. public interface UtenteUltraLightView { public boolean isNew(); public long getId(); Final implementation class. public String getNominativo(); public long getIdGruppo(); All fields private. } No mutable component. Mutators accessible only on implementation class, for web binding and in the Data Mapper Layer public class CentroFormController extends SimpleFormController{ public CentroFormController(){ setCommandClass(CentroImpl.class); setCommandName(Constant.CENTRO); setFormView(quot;admin/centroFormquot;); setSuccessView(Constant.REDIRECT_ELENCO_CENTRI); } ... } Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  25. 25. Data mapper The Data Mapper is a layer of software that separates the in- memory objects from the database. Its responsibility is to transfer data between the two and also to isolate them from each other. With Data Mapper the in-memory objects needn't know even that there's a database present; they need no SQL interface code, and certainly no knowledge of the database schema. (The database schema is always ignorant of the objects that use it.) Since it's a form of Mapper (473), Data Mapper itself is even unknown to the domain layer. http://martinfowler.com/eaaCatalog/dataMapper.html Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  26. 26. iBATIS mapping class - table <typeAlias type=quot;org.magicbox.domain.AmministratoreImplquot; alias=quot;adminquot;/> <typeAlias type=quot;org.magicbox.domain.AmministratoreLightImplquot; alias=quot;adminLightquot;/> <resultMap class=quot;adminLightquot; id=quot;resultAdminLightquot;> <result column=quot;idquot; property=quot;idquot; jdbcType=quot;INTEGERquot; /> <result column=quot;centroquot; property=quot;centroquot; jdbcType=quot;BIGINTquot; /> <result column=quot;nominativoquot; property=quot;nominativoquot; jdbcType=quot;VARCHARquot; /> </resultMap> <resultMap class=quot;adminquot; id=quot;resultAdminquot; extends=quot;resultAdminLightquot;> <result column=quot;emailquot; property=quot;emailquot; jdbcType=quot;VARCHARquot; /> <result column=quot;usernamequot; property=quot;usernamequot; jdbcType=quot;VARCHARquot; /> <result column=quot;cellularequot; property=quot;cellularequot; jdbcType=quot;VARCHARquot; /> </resultMap> <select id=quot;getAdminByUsernamequot; resultMap=quot;resultAdminquot;> SELECT id, centro, email, cellulare, nominativo, username FROM amministratori WHERE username = #username# </select> ... <insert id=quot;insertAdminquot; parameterClass=quot;adminquot;> <selectKey keyProperty=quot;idquot; resultClass=quot;longquot;> select nextval('amministratori_id_seq') </selectKey> INSERT INTO amministratori (id, centro, nominativo, email, username, cellulare) VALUES (#id:INTEGER#, #centro:BIGINT#, #nominativo:VARCHAR#, #email:VARCHAR#, #username:VARCHAR#, #cellulare:VARCHAR#) </insert> ... Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  27. 27. iBATIS Dao public class AmministratoriDaoImpl extends SqlMapClientDaoSupport implements AmministratoriDao{ public Integer deleteAmministratore(long idAdmin, long idCentro) throws DataAccessException{ Map map = new FastMap(); map.put(quot;idquot;, idAdmin); map.put(quot;centroquot;, idCentro); return getSqlMapClientTemplate().delete(quot;deleteAdminquot;, map); } public Long insertAmministratore(AmministratoreView admin) throws DataAccessException { return (Long)getSqlMapClientTemplate().insert(quot;insertAdminquot;, admin); } public Integer updateAmministratore(AmministratoreView admin) throws DataAccessException { return getSqlMapClientTemplate().update(quot;updateAdminquot;, admin); } public AmministratoreView getAmministratore(String username) throws DataAccessException{ return (AmministratoreView)getSqlMapClientTemplate().queryForObject(quot;getAdminByUsernamequot;, username); } .. } Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  28. 28. Transaction on service layer public class AmministratoriManagerImpl implements AmministratoriManager{ public long saveAmministratore(AmministratoreView admin) { return admin.isNew() ? amministratoriDao.insertAmministratore(admin) :amministratoriDao.updateAmministratore(admin); } public AmministratoreView getAmministratore(String username) { return amministratoriDao.getAmministratore(username); } public boolean deleteAmministratore(long idAdmin,long idCentro) { return amministratoriDao.deleteAmministratore(idAdmin, idCentro)== 1 ? true : false; } public List<AmministratoreView> getAmministratori() { return amministratoriDao.getAmministratori(); } Spring Way: declarative <bean name=quot;txAttributesquot; class=quot;org.springframework.transaction.interceptor.NameMatchTransactionAttributeSourcequot;> <property name=quot;propertiesquot;> <props> <prop key=quot;*quot;>PROPAGATION_SUPPORTS,readOnly</prop> <prop key=quot;save*quot;>PROPAGATION_REQUIRED,-Exception</prop> <prop key=quot;insert*quot;>PROPAGATION_REQUIRED,-Exception</prop> <prop key=quot;update*quot;>PROPAGATION_REQUIRED,-Exception</prop> <prop key=quot;delete*quot;>PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean> Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  29. 29. Test ! Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  30. 30. Demo MagicBox it' s a JEE solution to coordinate blood donations Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  31. 31. Q&A All this leads to great software projects Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  32. 32. Thanks for your attention Massimiliano Dessì desmax74 at yahoo.it http://wiki.java.net/bin/view/People/MassimilianoDessi http://www.jugsardegna.org/vqwiki/jsp/Wiki?MassimilianoDessi http://jroller.com/desmax Spring Framework Italian User Group http://it.groups.yahoo.com/group/SpringFramework-it Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License

×