SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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
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
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
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
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
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
                                                                     Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
                                                                     Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
MagicBox Project




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
                                                                     Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
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
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
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
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
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
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
XP View




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
                                                                     Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
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
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
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
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
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
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
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
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
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
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
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
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
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
Test !




Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group
Javaday Roma - 01/12/2007
                                                                     Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
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
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
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

Más contenido relacionado

Similar a Javaday Roma2007 Magic Box Kiss With Spring

Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Rick. Bahague
 

Similar a Javaday Roma2007 Magic Box Kiss With Spring (20)

Tapestry 5 in Action Pratica
Tapestry 5 in Action Pratica Tapestry 5 in Action Pratica
Tapestry 5 in Action Pratica
 
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
 
On our way to headless - A transition in progress
On our way to headless - A transition in progressOn our way to headless - A transition in progress
On our way to headless - A transition in progress
 
Eclipse@Rome 12 July 2007 Long Ver1
Eclipse@Rome 12 July 2007  Long Ver1Eclipse@Rome 12 July 2007  Long Ver1
Eclipse@Rome 12 July 2007 Long Ver1
 
Disassembling the Monolith: Taming Large Software Projects with Node.js
Disassembling the Monolith: Taming Large Software Projects with Node.jsDisassembling the Monolith: Taming Large Software Projects with Node.js
Disassembling the Monolith: Taming Large Software Projects with Node.js
 
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
 
DevOps - Keepers of the Keys to the Kingdom
DevOps - Keepers of the Keys to the KingdomDevOps - Keepers of the Keys to the Kingdom
DevOps - Keepers of the Keys to the Kingdom
 
Burckhardtsource.org: manual for scholars
Burckhardtsource.org: manual for scholarsBurckhardtsource.org: manual for scholars
Burckhardtsource.org: manual for scholars
 
DevOps Indonesia #12 - Adopting DevOps as culture using Azure DevOps
DevOps Indonesia #12 - Adopting DevOps as culture using Azure DevOpsDevOps Indonesia #12 - Adopting DevOps as culture using Azure DevOps
DevOps Indonesia #12 - Adopting DevOps as culture using Azure DevOps
 
*Source - towards the semantic annotation of digital content / Wittgenstein S...
*Source - towards the semantic annotation of digital content / Wittgenstein S...*Source - towards the semantic annotation of digital content / Wittgenstein S...
*Source - towards the semantic annotation of digital content / Wittgenstein S...
 
Make Tools
Make ToolsMake Tools
Make Tools
 
Introduction to Eclipse Che
Introduction to Eclipse CheIntroduction to Eclipse Che
Introduction to Eclipse Che
 
Spring Roo Internals Javaday IV
Spring Roo Internals Javaday IVSpring Roo Internals Javaday IV
Spring Roo Internals Javaday IV
 
Agile: Implications and Complications
Agile: Implications and Complications Agile: Implications and Complications
Agile: Implications and Complications
 
A Responsive Project Process
A Responsive Project ProcessA Responsive Project Process
A Responsive Project Process
 
Aspect Oriented Programming and MVC with Spring Framework
Aspect Oriented Programming and MVC with Spring FrameworkAspect Oriented Programming and MVC with Spring Framework
Aspect Oriented Programming and MVC with Spring Framework
 
Measuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb EditionMeasuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb Edition
 
Sakai spring maven archetype
Sakai spring maven archetypeSakai spring maven archetype
Sakai spring maven archetype
 
ABSE and AtomWeaver : A Quantum Leap in Software Development
ABSE and AtomWeaver : A Quantum Leap in Software DevelopmentABSE and AtomWeaver : A Quantum Leap in Software Development
ABSE and AtomWeaver : A Quantum Leap in Software Development
 
The Difference Between Your Project Succeeding or Burning To A Crisp Is Actua...
The Difference Between Your Project Succeeding or Burning To A Crisp Is Actua...The Difference Between Your Project Succeeding or Burning To A Crisp Is Actua...
The Difference Between Your Project Succeeding or Burning To A Crisp Is Actua...
 

Más de Massimiliano Dessì

Más de Massimiliano Dessì (20)

Code One 2018 maven
Code One 2018   mavenCode One 2018   maven
Code One 2018 maven
 
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
 
Hacking Maven Linux day 2017
Hacking Maven Linux day 2017Hacking Maven Linux day 2017
Hacking Maven Linux day 2017
 
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloud
 
Docker dDessi november 2015
Docker dDessi november 2015Docker dDessi november 2015
Docker dDessi november 2015
 
Docker linuxday 2015
Docker linuxday 2015Docker linuxday 2015
Docker linuxday 2015
 
Openshift linuxday 2014
Openshift linuxday 2014Openshift linuxday 2014
Openshift linuxday 2014
 
Web Marketing Training 2014 Community Online
Web Marketing Training 2014 Community OnlineWeb Marketing Training 2014 Community Online
Web Marketing Training 2014 Community Online
 
Vert.X like Node.js but polyglot and reactive on JVM
Vert.X like Node.js but polyglot and reactive on JVMVert.X like Node.js but polyglot and reactive on JVM
Vert.X like Node.js but polyglot and reactive on JVM
 
Reactive applications Linux Day 2013
Reactive applications Linux Day 2013Reactive applications Linux Day 2013
Reactive applications Linux Day 2013
 
Scala Italy 2013 extended Scalatra vs Spring MVC
Scala Italy 2013 extended Scalatra vs Spring MVCScala Italy 2013 extended Scalatra vs Spring MVC
Scala Italy 2013 extended Scalatra vs Spring MVC
 
Codemotion 2013 scalatra_play_spray
Codemotion 2013 scalatra_play_sprayCodemotion 2013 scalatra_play_spray
Codemotion 2013 scalatra_play_spray
 
Why we cannot ignore functional programming
Why we cannot ignore functional programmingWhy we cannot ignore functional programming
Why we cannot ignore functional programming
 
Scala linux day 2012
Scala linux day 2012 Scala linux day 2012
Scala linux day 2012
 
Three languages in thirty minutes
Three languages in thirty minutesThree languages in thirty minutes
Three languages in thirty minutes
 
MongoDB dessi-codemotion
MongoDB dessi-codemotionMongoDB dessi-codemotion
MongoDB dessi-codemotion
 
MongoDB Webtech conference 2010
MongoDB Webtech conference 2010MongoDB Webtech conference 2010
MongoDB Webtech conference 2010
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Spring Roo JaxItalia09
Spring Roo JaxItalia09Spring Roo JaxItalia09
Spring Roo JaxItalia09
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Javaday Roma2007 Magic Box Kiss With Spring

  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Test ! Massimiliano Dessì - desmax74@yahoo.it – SpringFramework Italian User Group Javaday Roma - 01/12/2007 Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
  • 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. 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. 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