SlideShare une entreprise Scribd logo
1  sur  39
@Diego	
  Thanh	
  Nguyen	
  -­‐	
  http://free.smartbiz.vn	
  
J2EE	
  DESIGN	
  PATTERN	
  



10/8/12	
                         www.smartbiz.vn	
               1	
  
Table	
  Of	
  Content	
  
q I.	
  GoF	
  Design	
  Pattern	
  
    v I.1.	
  Creation	
  Patterns	
  
    v I.2.	
  Structural	
  Patterns	
  
    v I.3.	
  Behavioral	
  Patterns	
  
q II.	
  J2EE	
  Presentation:	
  	
  
q III.	
  J2EE	
  Business:	
  	
  
q IV.	
  J2EE	
  Integration	
  




  10/8/12	
                       www.smartbiz.vn	
     2	
  
I.	
  How	
  Design	
  Patterns	
  Arise	
  ?	
  
                                                    Pattern
                      	
  1.	
                                      Context
                   Problem	
                                              a design situation giving rise to a design problem
                          	
  
                                                                    Problem
                                                                           a set of forces occuring in that context
                                                                     Solution
                   2.	
  Context	
  
                                                                        a form or rule that can be applied to resolve these forces
                                       Forces	
  

                                                      IF	
  	
  you	
  Nind	
  yourself	
  in	
  CONTEXT	
  
                       3.	
                           	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  for	
  example	
  EXAMPLES,	
  
                    Solution	
                        	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  with	
  PROBLEM,	
  
                        	
                            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  entailing	
  FORCES	
  
                                                      THEN	
  	
  for	
  some	
  REASONS,	
  
                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  apply	
  DESIGN	
  FORM	
  AND/OR	
  RULE	
  
BeneFits	
                       Consequences	
  
                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  to	
  construct	
  SOLUTION	
  
                Related	
  Patterns	
                 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  leading	
  to	
  NEW	
  CONTEXT	
  &	
  OTHER	
  PATTERNS	
  


  10/8/12	
                                         www.smartbiz.vn	
                                                                                         3	
  
I.	
  Design-­‐Pattern	
  Catalog	
  
     !                !                                                                Purpose!

                                                 Creational!                   Structural!                     Behavioral!

                      Class!             • Factory!Method!                • Adapter!              • Interperter!

                                         •   Singleton!                   •   Façade!             •   Observer!
                                         •   Factory!                     •   Decorator!          •   Command!
                                         •   Abstract!Factory!            •   Composite!          •   Iterator!
     Scope!                              •   Builder!                     •   Adapter!            •   Chain!of!Responsibility!
                      Object!            •   Prototype!                   •   Bridge!             •   Mediator!
                                         •   Object!Pool!                 •   Flyweight!          •   Momento!
                                                                          •   Proxy!              •   State!
                                                                                                  •   Strategy!
                                                                                                  •   Visitor!
 !
 !            Defer	
  object	
  creation	
  to	
  	
                                      Describe	
  algorithms	
  and	
  	
  
              another	
  object	
                                                          Nlow	
  control	
  
                                                          Describe	
  ways	
  to	
  	
  
                                                          assemble	
  objects	
  


10/8/12	
                                                        www.smartbiz.vn	
                                                 4	
  
I.1.	
  Creation	
  Patterns	
  
q Creational	
  Patterns	
  	
  prescribe	
  the	
  way	
  
   that	
  objects	
  are	
  created.	
  These	
  patterns	
  are	
  
   used	
  when	
  a	
  decision	
  must	
  be	
  made	
  at	
  the	
  
   time	
  a	
  class	
  is	
  instantiated.	
  	
  
q Singleton:	
  ensure	
  a	
  class	
  has	
  one	
  Instance,	
  
   and	
  provide	
  a	
  global	
  point	
  of	
  access	
  to	
  it.	
  
q Abstract	
  Factory:	
  provide	
  an	
  interface	
  for	
  
   creating	
  families	
  of	
  related	
  or	
  dependent	
  
   objects	
  without	
  specifying	
  their	
  concrete	
  
   classes.	
  
10/8/12	
                      www.smartbiz.vn	
                         5	
  
I.1.1	
  Abstract	
  Factory	
  
q  Intent:	
  create	
  families	
  of	
  related	
  objects	
  without	
  
    specifying	
  subclass	
  names	
  
q  Applicability:	
  when	
  clients	
  cannot	
  anticipate	
  
    groups	
  of	
  classes	
  to	
  instantiate	
  
q  Concrete	
  factories	
  create	
  groups	
  of	
  strategies	
  	
  




10/8/12	
                        www.smartbiz.vn	
                             6	
  
I.2.	
  Structural	
  Patterns	
  
q Structural	
  Patterns	
  	
  prescribe	
  the	
  
   organization	
  of	
  classes	
  and	
  objects.	
  
q Adapter	
  
       v 	
  Convert	
  the	
  interface	
  of	
  a	
  class	
  into	
  another	
  
           interface	
  that	
  clients	
  expect	
  
       v 	
  Adapter	
  lets	
  classes	
  work	
  together	
  that	
  couldn’t	
  
           otherwise	
  because	
  of	
  incompatible	
  interfaces	
  
q Decorator	
  
       v 	
  Extend	
  the	
  functionality	
  of	
  the	
  original	
  class	
  in	
  a	
  
           way	
  that	
  is	
  transparent	
  to	
  the	
  client	
  class	
  
10/8/12	
                               www.smartbiz.vn	
                                 7	
  
I.2.1.	
  Composite	
  
q Intent	
  
   v treat	
  individual	
  objects	
  &	
  multiple,	
  recursively-­‐
      composed	
  objects	
  uniformly	
  
q Applicability	
  
   v Objects	
  must	
  be	
  composed	
  recursively,	
  
   v and	
  no	
  distinction	
  between	
  individual	
  &	
  composed	
  
      elements,	
  
   v and	
  objects	
  in	
  structure	
  
      can	
  be	
  treated	
  uniformly	
  


   10/8/12	
                      www.smartbiz.vn	
                        8	
  
I.2.1.	
  Composite	
  
   q CORBA	
  Naming	
  Service	
  example	
  using	
  
      CosNaming::BindingIterator	
  (which	
  is	
  an	
  
      example	
  of	
  the	
  “Batch	
  Iterator”	
  pattern	
  
      compound	
  from	
  POSA5)	
  




Composite	
  
  Node	
                                                    Leaf	
  Node	
  
   10/8/12	
                  www.smartbiz.vn	
                          9	
  
I.3.	
  Behavioral	
  Patterns	
  
q Behavioral Patterns prescribe the way
   objects interact with each other. They help
   make complex behavior manageable by
   specifying the responsibilities of objects and
   the ways they communicate with each other.
q State:	
  allow	
  an	
  object	
  to	
  alter	
  its	
  behavior	
  
   when	
  its	
  internal	
  state	
  changes	
  




10/8/12	
                      www.smartbiz.vn	
                           10	
  
I.3.1.	
  Strategy	
  
q Intent	
  
    v  deNine	
  a	
  family	
  of	
  algorithms,	
  encapsulate	
  each	
  one,	
  &	
  
        make	
  them	
  
    v  interchangeable	
  to	
  let	
  clients	
  &	
  algorithms	
  vary	
  
        independently	
  
q Applicability	
  
    v  When	
  object	
  is	
  conNigurable	
  with	
  one	
  of	
  many	
  algorithms,	
  
    v  and	
  all	
  algorithms	
  can	
  be	
  encapsulated,	
  
    v  and	
  one	
  interface	
  covers	
  all	
  encapsulations	
  	
  




  10/8/12	
                               www.smartbiz.vn	
                                  11	
  
I.3.1.	
  Strategy	
  
q Strategy	
  applied	
  in	
  distributed	
  (middleware)	
  

      Hook	
  for	
  
      marshaling	
                                            Hook	
  for	
  
      strategy	
                                              the	
  request	
  
                                                              demuxing	
  
                            Hook	
  for	
  the	
  event	
     strategy	
  
                            demuxing	
  strategy	
  


   Hook	
  for	
  the	
                                          Hook	
  for	
  the	
  
   connection	
                                                  concurrency	
  
   management	
                                                  strategy	
  
   strategy	
  


                                                                   Hook	
  for	
  the	
  
                                                                   underlying	
  
                                                                   transport	
  
                                                                   strategy	
  



10/8/12	
                           www.smartbiz.vn	
                           12	
  
I.3.1.	
  Oracle	
  Fusion	
  Component	
  
OracleFusion Groupware API: A unified interface for all connectors that
access the groupware servers via WebDAV, applying Singleton, Façade and
Factory design patterns


                                                               All connectors utilize the Jakarta
                EnterConnect Groupware API
                                                               Jackrabbit (client-side) API to
                                                               send requests to and receive
    Exchange          OpenGroupware        Lotus Domino        responses from a variety of
    Connector           Connector           Connector          WebDAV-enabled groupware
                                                               servers      MS Exchange 2003

                                                                                                         Email
                      Jakarta Slide API




                                                                               WebDAV Server
                                                            XML HTTP request                            Calendar
  Jakarta Commons HTTP Client         JDOM (JSR 102)
                                                                                                        Contact
                                                           XML HTTP response
   Jakarta Commons Logging          Java Transaction API                                                 Task

                                                                                                    Uploaded
                                                                                                    Document




Jakarta Jackrabbit re-uses some of open source libraries such as the
Jakarta Commons library (HTTP Client &Logging), JDOM (JSR 102), JTA, JMX, …

                                                                                               13	
  
I.3.2.	
  OF	
  Design	
  Pattern	
  
q Singleton:	
  the	
  Connector	
  class	
  must	
  only	
  have	
  one	
  instance	
  because	
  it’s	
  wasteful	
  &                                    	
  
   useless	
  to	
  keep	
  several	
  instances	
  on	
  memory.	
  Keeping	
  so	
  many	
  connectors	
  will	
  difNicult                               	
  
   to	
  manage	
  lifecycle	
  &	
  impact	
  the	
  performance	
  of	
  application.	
  
q Factory	
  Method:	
  because	
  of	
  we	
  assume	
  our	
  API	
  can	
  be	
  used	
  against	
  multiple	
  servers                                  	
  
   so	
   that	
   there	
   must	
   be	
   a	
   Connector	
   for	
   each	
   server	
   (i.e.	
   ECExchangeConnector,                                 	
  
   ECLotusDominoConnector,	
   ECOpenGroupwareConnector).	
   Each	
   connector	
   is                                                                     	
  
   responsible	
   for	
   manufacturing	
   its	
   own	
   managers	
   (MailManager,	
   CalendarManager,                                                	
  
   TasksManager)	
  and	
  delegate	
  the	
  jobs	
  to	
  them.	
  The	
  connector	
  will	
  only	
  be	
  determined                                   	
  
   by	
  the	
  client	
  depending	
  on	
  the	
  conNiguration.	
  
    v For	
   example,	
   if	
   a	
   client	
   (portlet)	
   need	
   to	
   send	
   a	
   mail	
   by	
   Exchange	
   server	
   then	
   it	
   will
                                                                                                                                                            	
  
          call	
   the	
   ECExchangeConnector;	
   this	
   connector	
   then	
   will	
   use	
   its	
   localized	
   manager                          	
  
          ExchangeMailManager	
  to	
  make	
  life	
  easier.	
  
q Abstract	
  Factory:	
  ECGroupwareFactory	
  is	
  the	
  abstract	
  factory	
  class	
  for	
  all	
  connectors                                       	
  
   because	
  it	
  will	
  expose	
  a	
  uniFied	
  interface	
  for	
  connectors	
  to	
  client.	
  
q Facade:	
   the	
   uniFied	
   interface	
   will	
   be	
   deFined	
   in	
   the	
   Façade	
   pattern.	
   As	
   stated                            	
  
   before,	
   a	
   speciNic	
   Connector	
   will	
   delegate	
   the	
   appropriate	
   jobs	
   to	
   its	
   subsystems                            	
  
   (managers).	
  The	
  façade	
  pattern	
  also	
  decouples	
  the	
  managers	
  from	
  the	
  client	
  and	
  other                                 	
  
   managers,	
  thereby	
  promoting	
  independence	
  and	
  portability.	
  
           10/8/12	
                                                 www.smartbiz.vn	
                                                          14	
  
I.3.1.	
  OF	
  Design	
  Pattern	
  
                                                           <<Factory Method>>
                                                                                                              «interface»
                                                                                                            TasksManager


                                   <<Abstract Factory>>

                             ECGroupwareFactory
                                                                                               <<Façade>>
                                                                                                       ExchangeTasksManager




                                                                     <<Singleton>>
    ECLotusDominoConnector    ECOpenGroupwareConnector           ECExchangeConnector                 ExchangeCalendarManager




                                                                                ExchangMailManager




                                                                                      «interface»           «interface»
                                                                                     MailManager         CalendarManager




                                                                                                      Apache Slide Class




                                                                                                                15	
  
10/8/12	
                                                 www.smartbiz.vn	
  
I.4.1.	
  Observer	
  Pattern	
  
q Easier	
  to	
  keep	
  a	
  consistent	
  and	
  maintainable	
  
   view	
  of	
  the	
  data	
  
      v Half	
  as	
  many	
  connections	
  between	
  actions,	
  views	
  
      v Views	
  are	
  independent	
  and	
  unaware	
  of	
  each	
  other	
  



                                                                                                                                       Data	
  


    Action	
              Action	
               Action	
           Action	
                           Action	
             Action	
              Action	
     Action	
  

              View	
  à	
  	
  View	
  &	
  Action	
  à	
  	
                                    Data	
  notiNies	
  observers	
  via	
  events	
  
              View	
  Messages	
  about	
  the	
  data	
                                           when	
  the	
  state	
  of	
  the	
  data	
  changes	
  



10/8/12	
                                                                        www.smartbiz.vn	
                                                                      16	
  
I.4.2.	
  Implementing	
  an	
  Observer	
  
                                                      1.  Assign	
  the	
  subject	
  to	
  the	
  
                                                          observers	
  (MainForm_Load)	
  




	
  
	
  


                     IssueSubject	
  
                          	
  
                          	
  
                          	
  

       10/8/12	
                        www.smartbiz.vn	
                                   17	
  
I.4.3.	
  Implementing	
  an	
  Observer	
  
                                           1.  Assign the subject to the
                                               observers (MainForm_Load)
                                                   m_subject = new IssueSubject()
                                                   paneA.Subject = m_subject
b                                                  paneB.Subject = m_subject ...

                 c           d

a


              IssueSubject




10/8/12	
                    www.smartbiz.vn	
                              18	
  
I.4.4.	
  Implementing	
  an	
  Observer	
  
                                            1.  Assign the subject to the
                                                observers (MainForm_Load)
                                                    m_subject = new IssueSubject()
                                                    paneA.Subject = m_subject
 b                                                  paneB.Subject = m_subject ...

                  c           d             2.  Observers bind and save
                                                changes to Subject.DataSet
 a


               IssueSubject




 10/8/12	
                    www.smartbiz.vn	
                              19	
  
I.4.5.	
  Implementing	
  an	
  Observer	
  
                                                        1.  Assign	
  the	
  subject	
  to	
  the	
  
                                                            observers	
  (MainForm_Load)	
  
                                                                m_subject	
  =	
  new	
  IssueSubject()	
  
                                                                paneA.Subject	
  =	
  m_subject	
  
                                                                paneB.Subject	
  =	
  m_subject	
  ...	
  
       b	
                                                      	
  
                         c	
            d	
             2.  Observers	
  bind	
  and	
  save	
  
                                                            changes	
  to	
  Subject.DataSet	
  
       a	
                                              3.  When	
  data	
  changes,	
  subject	
  
	
                                                          raises	
  DataChanged	
  event	
  
	
  


                     IssueSubject	
  
                          	
  
                          	
  
                          	
  

       10/8/12	
                          www.smartbiz.vn	
                                                   20	
  
I.4.6.	
  Implementing	
  an	
  Observer	
  
                                                        1.  Assign	
  the	
  subject	
  to	
  the	
  
                                                            observers	
  (MainForm_Load)	
  
                                                                     m_subject	
  =	
  new	
  IssueSubject()	
  
                                                                     paneA.Subject	
  =	
  m_subject	
  
       b	
                                                           paneB.Subject	
  =	
  m_subject	
  ...	
  

                         c	
            d	
             2.  Observers	
  bind	
  and	
  save	
  
                                                            changes	
  to	
  Subject.DataSet	
  
       a	
                                              3.  When	
  data	
  changes,	
  subject	
  
	
                                                          raises	
  DataChanged	
  event	
  
	
                                                              	
  	
  
                                                        4.  Observers	
  handle	
  subject	
  
                                                        	
  
                                                             events	
  to	
  rebind	
  data,	
  if	
  
                     IssueSubject	
                          they	
  care	
  
                                                             	
  
                          	
                                         m_subject.DataChanged	
  +=	
  …	
  
                          	
                                         ‘	
  rebind	
  
                          	
  

       10/8/12	
                          www.smartbiz.vn	
                                                        21	
  
I.5.1.	
  Coordinate	
  Command	
  State	
  
q Related	
  menu	
  and	
  toolbar	
  widgets	
  are	
  not	
  
   automatically	
  handled	
  together	
  
q Command	
  Pattern	
  
      v  Command	
  objects	
  unify	
  the	
  state	
  and	
  action	
  for	
  related	
  
          UI	
  widgets	
  	
  
q Example:	
  
      v “Save”	
  action	
  
              Ø  Menu	
  item	
  
              Ø  Toolbar	
  button	
  
              Ø  Context	
  menu	
  	
  


10/8/12	
                                   www.smartbiz.vn	
                              22	
  
I.5.2.	
  Implementing	
  a	
  Command	
  

 1.  Create	
  a	
  Command	
  for	
  each	
  action	
  in	
  MainForm_Load()	
  
            action	
  =	
  new	
  Command.Action(this.WorkOfNline_Action)	
  
            ofNlineCommand	
  =	
  new	
  Command(action)	
  

 2.  Wire	
  menu	
  items	
  and	
  toolbar	
  buttons	
  to	
  the	
  Command	
  
     using	
  Commander	
  objects	
  
            MenuItemCommander.Connect(menuWorkOfNline,	
  ofFlineCommand	
  )	
  
            ToolBarButtonCommander.Connect(tlbOfNline,	
  ofFlineCommand	
  )	
  
	
  
	
  3.  Control	
  button	
  and	
  menu	
  item	
  state	
  through	
  the	
  
           Command	
  
           '	
  Disable	
  all	
  UI	
  widgets	
  connected	
  to	
  this	
  command	
  
           ofNlineCommand.IsEnabled	
  =	
  false	
  


       10/8/12	
                                            www.smartbiz.vn	
               23	
  
I.6.1.	
  Accelerated	
  J2EE	
  Development	
  
q Architect	
  Service-­‐Oriented	
  Components	
  
       v  Design	
  for	
  Flexible,	
  Agile	
  Applications	
  and	
  	
  
           Iterative	
  Development	
  
q Apply/Extend	
  Pre-­‐Built	
  COTS	
  Components	
  
       v  Infrastructure	
  and	
  Common	
  Business	
  Components	
  
q Generate/Extend	
  Custom	
  Components	
  
       v  Rapidly	
  Specify	
  and	
  Provision	
  New	
  Components	
  
q Leverage	
  Industry	
  Development	
  Standards	
  
       v  Frameworks	
  (STRUTS,	
  Spring	
  /	
  Weld,	
  Hibernate)	
  
       v  Patterns	
  (MVC)	
  
       v  XML,	
  Best	
  Practices	
  

10/8/12	
                                 www.smartbiz.vn	
                     24	
  
II.	
  J2EE	
  Application	
  Design	
  Patterns	
  
                                                                                                                                             Business	
  Logic	
  &	
                                                                                       Data	
  Integration	
  
                                Presentation	
  
                                                                                                                                             Messaging	
  Fabric	
                                                                                           &	
  Persistence	
  
                                                                                                             EJB	
  Container	
                                                                                                   EJB	
  Container	
  
                           Response	
  
                                                                                                                      8.	
  
                                                                                                                      Execute	
  
                                                                                                                                                           Business	
  
                                                                                                                                                                                                                                                                                    Resources	
  
                                                                                                                      Biz	
  Method	
                                                                                             13.	
  
                                                    Request	
                                                                                               Service	
                                                                                             14.	
  
                                                                                                                                                                                                                                  CRUD	
  
                                                                                                                                                            Facade	
                              10b.	
                          Data	
           Data	
         Query	
  
                                                                                                                                                                     9.	
                         Get/Set	
                                       Access	
                                Database	
  
                                                                                                                               <<de-­‐serialize>>	
  
Web	
  Server	
  &	
                                        18.	
  Response	
                                                                                        Assemble	
                   Remove	
                                        Object	
  
                                                                                                                   Serialized	
  
                                                                                                                                                                                                                       RMI	
  
                                                                                                                                                                                                                                                                                                         JMS	
  
Servlet	
  Engine	
                                                                                                  Value	
  
                                                                                                                                                                     Data	
  
                                                                                                                                                                                                                                                                                Directory	
  
                                                                                                                     Object	
  
                                            16.	
  Forward	
                        JSF,	
  JSP	
  




                                                                                                                                                                                                                        JMS	
  
                                                                                   (Taglibs)	
                               <<creates>>	
                  Value	
                                                               12.	
  
       1.	
  Request	
                                                                                                                                      Object	
                                                              Get/Set	
  
                                                                      17.	
  State?	
                                                                     Assembler	
                                                                                       <<uses>>	
  
                                     Action	
                                                                                                                                                                                     Remove	
  
                                                                                                                                                                                                      Data	
  
                                     Servlet	
                                                                                                                       10a.	
                          Access	
                                                                         <<uses>>	
  
                                                                                                                                                                     Invoke	
                        Proxy	
  
                       4.	
  Dispatch	
                            2.	
  Fill	
  State	
                                                                                                                                                                                Data	
  
     XML	
                                                                                                                                                                             11.	
                                                 Entity	
                                                 Connection	
  
                                                                   3.	
  Validate	
                                                                                                    CRUD	
                                                                        Connection	
  
   Action	
  to	
                                                                                                                                                                                                                            Bean	
  	
                                                  Pool	
  
                                                                                                                                                          (Stateless)	
                Data	
                                                                          Factory	
  
   Form	
  	
  &	
                                                                                                              Value	
  
                                                                                                                                                            Session	
  
   Forward	
            <<uses>>	
                                                                                              Object	
  
                                                                                                                                                             Bean	
  
   Mappings	
  
                                                                                      Action	
  
                                                                                      Form	
  
    5.	
  Get	
  Delegate	
          Action	
  
                                     Object	
          15.	
  Fill	
  State	
                <<uses>>	
                                               Key	
                                                                Other	
  Infrastructure	
  
                                             6.	
  Execute	
  

                                                                                                                                                                                                          	
  
                  <<supplies>>	
                                                                                  RMI	
  
    Business	
                      Business	
            <<uses>>	
                                                                                                         EJB	
  Container
                                                                                      Value	
                                                          Model	
  
    Delegate	
                      Delegate	
                                                                                               M	
  
                                                                                                                   JMS	
  




                                                                                      Object	
                                                         Pattern	
  
    Factory	
                       Adapter	
  
                                             7a.	
                                                                                                                                     Event	
                            Security	
                            Messaging	
                            Event	
  
                                             Execute	
                                                                                                 View	
                       Interceptor	
                       Management	
                            Command	
                           NotiFication	
  
                                             Biz	
  Method	
                        Business	
  
                                                                                                                                              V	
      Pattern	
                    Framework	
                         Framework	
                              Factory	
                          Framework	
  
                                                                                     Service	
  
                                                                                      Proxy	
                                                                                                           <<uses>>	
  
                                                                                                                                                       Controller	
  
                                                                                                                                              C	
      Pattern	
  
                                                                                                                                                                                                                                                                <<uses>>	
  

                                               7b.	
  CRUD	
  Data	
                   Data	
                                                                                                                                                                                    Message	
  Q	
  
                                                                                                                                                                                                          Filter	
                            Service	
  
                                                                                      Access	
                                                                                                                                                                                   &	
  Channel	
  
                                                                                                                                                       Other	
                                        Interceptors	
                         Activation	
  
                                                                                      Proxy	
  
                                                                                                            To	
  DAO	
  
                                                                                                                                              P	
      Pattern	
  
                                                                                                                                                                                                                                                                                  Locator	
  




      10/8/12	
                                                                                                                               www.smartbiz.vn	
                                                                                                                                            25	
  
II.	
  Model-­‐View-­‐Controller	
  –	
  Passive	
  


                       :Controller                 :Model                  :View

              handleEvent

                                 service




                                       update
                                                                 getData




10/8/12	
                                  www.smartbiz.vn	
                       26	
  
II.	
  Model-­‐View-­‐Controller	
  –	
  Active	
  
                                                          Controller

                                   <<interface>>
                                     Observer
                     Model
                                      +update()


                                                                View



                             :Model                     :View
              handleEvent
                                             notify

                                           update
                                              getData

                                                data




10/8/12	
                        www.smartbiz.vn	
                     27	
  
II.1.	
  Presentation	
  Tier	
  Patterns	
  
q Intercepting	
  Filter	
  
q Front	
  Controller:	
  Use	
  of	
  a	
  Controller	
  to	
  
   handle	
  all	
  web	
  requests	
  
q Dispatcher	
  View:	
  The	
  controller	
  works	
  with	
  
   a	
  Dispatcher	
  that	
  handles	
  navigation	
  
q Composite	
  View	
  
q View	
  Helper	
  
q Service	
  to	
  Worker	
  


10/8/12	
                  www.smartbiz.vn	
                   28	
  
II.2.	
  Intercepting	
  Filter	
  
q Problems:	
  
       v Verify	
  authentication	
  
       v Check	
  type	
  of	
  client	
  
       v Is	
  the	
  session	
  valid?	
  	
  	
  
q Solution:	
  implement	
  one	
  or	
  more	
  
   Intercepting	
  Nilters.	
  
q Sample:	
  Filter-­‐servlet	
  -­‐	
  can	
  transparently	
  
   pre	
  and	
  post	
  process	
  all	
  requests	
  in	
  an	
  
   unlimited	
  length	
  Nilter	
  chain.	
  

10/8/12	
                                   www.smartbiz.vn	
         29	
  
II.3.	
  Front	
  Controller	
  &	
  Dispatcher	
  
q Front	
  Controller	
  -­‐	
  Problems:	
  
       v Multiple	
  views.	
  
       v Navigation	
  logic	
  embedded	
  in	
  views.	
  
       v DifNicult	
  to	
  maintain	
  view	
  logic	
  as	
  application	
  
          grows.	
  
       v Want	
  to	
  reuse	
  view	
  navigation	
  within	
  multiple	
  
          clients.	
  




10/8/12	
                           www.smartbiz.vn	
                         30	
  
II.3.	
  Front	
  Controller	
  -­‐	
  Dispatcher	
  
Client        FrontController              Dispatcher                           Vi ew   Helper

     1: Send Request


                        1.1: Delegate Request


                                                       1.1.1: Forward Request




     2: Send Request




                                       2.1: Forward Request




     3: Send Request




                                                  3.1: Process Request




10/8/12	
                                  www.smartbiz.vn	
                              31	
  
III.4.	
  View	
  Helper	
  
q Problem:	
  
       v Many	
  common	
  operations	
  in	
  each	
  view.	
  
       v Often	
  view	
  output	
  is	
  dependant	
  on	
  business	
  
          data.	
  
       v Create	
  more	
  cohesive	
  look	
  and	
  feel.	
  
       v Like	
  to	
  hand	
  off	
  UI	
  to	
  web	
  design	
  group	
  
q Solution:	
  
       v Basically	
  anything	
  that	
  helps	
  you	
  display	
  your	
  
          model	
  data	
  in	
  a	
  reusable	
  fashion.	
  
       v Implemented	
  as	
  JavaBeans,	
  Tags	
  or	
  XML/XSLT	
  
q See	
  the	
  JSTL,	
  JSF	
  and	
  Struts.	
  
10/8/12	
                           www.smartbiz.vn	
                           32	
  
II.5.	
  Composite	
  View	
  
 q Problem:	
  
         v Many	
  common	
  &	
  recurring	
  components	
  in	
  a	
  view.	
  	
  
         v Fragments	
  may	
  display	
  differently	
  given	
  user	
  type	
  
            (i.e.	
  faculty,	
  student).	
  
         v Look	
  and	
  feel	
  in	
  Nlux	
  needs	
  to	
  be	
  easily	
  
            updateable.	
  
 q Differs	
  from	
  View	
  Helper	
  as	
  the	
  Composite	
  
    View	
  decides	
  which	
  sub-­‐views	
  to	
  include	
  
    while	
  View	
  Helper	
  generally	
  decides	
  how	
  to	
  
    display	
  a	
  given	
  sub-­‐view.	
  
10/8/12	
                            www.smartbiz.vn	
                         33	
  
III.	
  Business	
  Tier	
  Patterns	
  
q  Business	
  Delegate:	
  use	
  of	
  a	
  Business	
  Delegate	
  to	
  
    hide	
  Implementation	
  Detail.	
  
q Session	
  Façade	
  
q Service	
  Locator	
  
q Value	
  Object	
  
q Composite	
  Entity	
  
q Value	
  Object	
  Assembler	
  
q Value	
  List	
  Handler	
  


10/8/12	
                         www.smartbiz.vn	
                             34	
  
III.1.	
  Business	
  Delegate	
  
    Cl ient                                                                                            BusinessService



              1: Creat e wi th ID        BusinessDelegate



                                                  1.1: Convert ID to Handle




                                                                                Handle
                                                            1.1.1: Create




                             2: Invoke
                                                   2.1: Get Business Service


                                                                                          2.1. 1: Connect



                                                 2.1. 2: Return Business Service




                                                                            2.2: Invoke




10/8/12	
                                          www.smartbiz.vn	
                                                     35	
  
III.2.	
  Session	
  Façade	
  Pattern	
  
q Problem:	
  
       v Need	
  very	
  loose	
  coupling	
  between	
  client	
  and	
  
          ever	
  changing	
  business	
  tier.	
  
       v Data	
  tier	
  changing;	
  need	
  to	
  improve	
  reuse.	
  
q Session	
  Bean	
  	
  
                                                                     EJB Tier
   provides	
  uniNied	
  approach	
  
q Façade	
  hides	
  	
  
   Entity	
  Bean	
  Details	
  
                                                           Session
                            Client                                              Entity Bean
                                                            Bean




10/8/12	
                            www.smartbiz.vn	
                                 36	
  
IV.	
  Integration	
  
q Data	
  Access	
  Object	
  
q Service	
  Activator	
  
q User	
  WorkNlow	
  Integrator	
  




10/8/12	
                 www.smartbiz.vn	
     37	
  
IV.1.	
  Data	
  Access	
  Object	
  
     Business                                                 DataAcces
                             accesses
      Object                                                   sObject

                  inherits     inherits            inherits




         Oracle                                                Sybase
                             DB2DAO
          DAO                                                   DAO



         adapts                 adapts                         adapts



      Oracle                   DB2                             Sybase
     Database                Database                         Database

10/8/12	
                    www.smartbiz.vn	
                          38	
  
10/8/12	
     www.smartbiz.vn	
     39	
  

Contenu connexe

Similaire à GoF J2EE Design Patterns

Framework Engineering_Final
Framework Engineering_FinalFramework Engineering_Final
Framework Engineering_Final
YoungSu Son
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
Design patterns
Design patternsDesign patterns
Design patterns
Alok Guha
 
Using mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite uiUsing mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite ui
Nish Anil
 
Designpatterns
DesignpatternsDesignpatterns
Designpatterns
reynolds
 

Similaire à GoF J2EE Design Patterns (20)

Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Framework Engineering_Final
Framework Engineering_FinalFramework Engineering_Final
Framework Engineering_Final
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Dan Haywood
Dan HaywoodDan Haywood
Dan Haywood
 
Using mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite uiUsing mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite ui
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Structure mapping your way to better software
Structure mapping your way to better softwareStructure mapping your way to better software
Structure mapping your way to better software
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
 
Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012
 
Design Patterns Course
Design Patterns CourseDesign Patterns Course
Design Patterns Course
 
Dependency Inversion in large-scale TypeScript applications with InversifyJS
Dependency Inversion in large-scale TypeScript applications with InversifyJSDependency Inversion in large-scale TypeScript applications with InversifyJS
Dependency Inversion in large-scale TypeScript applications with InversifyJS
 
AngularJS Scopes
AngularJS ScopesAngularJS Scopes
AngularJS Scopes
 
Framework Engineering
Framework EngineeringFramework Engineering
Framework Engineering
 
Designpatterns
DesignpatternsDesignpatterns
Designpatterns
 
Lightweight Classifications
Lightweight ClassificationsLightweight Classifications
Lightweight Classifications
 
Introduction To Design Patterns Class 4 Composition vs Inheritance
 Introduction To Design Patterns Class 4 Composition vs Inheritance Introduction To Design Patterns Class 4 Composition vs Inheritance
Introduction To Design Patterns Class 4 Composition vs Inheritance
 

Plus de Thanh Nguyen

Plus de Thanh Nguyen (20)

Building a NFT Marketplace DApp
Building a NFT Marketplace DAppBuilding a NFT Marketplace DApp
Building a NFT Marketplace DApp
 
Serverless Architecture 101 ⚡
Serverless Architecture 101 ⚡Serverless Architecture 101 ⚡
Serverless Architecture 101 ⚡
 
The fundamentals of AWS Cloud Security 🛠⛅️🚀
The fundamentals of AWS Cloud Security 🛠⛅️🚀The fundamentals of AWS Cloud Security 🛠⛅️🚀
The fundamentals of AWS Cloud Security 🛠⛅️🚀
 
Migrating Monolithic Applications with the Strangler Pattern
Migrating Monolithic Applications with the Strangler Pattern Migrating Monolithic Applications with the Strangler Pattern
Migrating Monolithic Applications with the Strangler Pattern
 
E301 Elastic Beanstalk PaaS
E301 Elastic Beanstalk PaaSE301 Elastic Beanstalk PaaS
E301 Elastic Beanstalk PaaS
 
Serverless Data Lake on AWS
Serverless Data Lake on AWSServerless Data Lake on AWS
Serverless Data Lake on AWS
 
SmartChat WhatsApp-clone using AWS Amplify AppSync
SmartChat WhatsApp-clone using AWS Amplify AppSyncSmartChat WhatsApp-clone using AWS Amplify AppSync
SmartChat WhatsApp-clone using AWS Amplify AppSync
 
Introduction to Ethereum Blockchain & Smart Contract
Introduction to Ethereum Blockchain & Smart ContractIntroduction to Ethereum Blockchain & Smart Contract
Introduction to Ethereum Blockchain & Smart Contract
 
Amazon AWS Free-Tier
Amazon AWS Free-TierAmazon AWS Free-Tier
Amazon AWS Free-Tier
 
Rapid Software Development Process
Rapid Software Development ProcessRapid Software Development Process
Rapid Software Development Process
 
PMI ACP Classroom Question Paper
PMI ACP Classroom Question PaperPMI ACP Classroom Question Paper
PMI ACP Classroom Question Paper
 
PMI ACP Classroom Question Paper with Answers
PMI ACP Classroom Question Paper with AnswersPMI ACP Classroom Question Paper with Answers
PMI ACP Classroom Question Paper with Answers
 
PMI-ACP Case Study
PMI-ACP Case StudyPMI-ACP Case Study
PMI-ACP Case Study
 
PMI-ACP Lesson 12 Knowledge and Skills Nugget 4
PMI-ACP Lesson 12 Knowledge and Skills Nugget 4PMI-ACP Lesson 12 Knowledge and Skills Nugget 4
PMI-ACP Lesson 12 Knowledge and Skills Nugget 4
 
PMI-ACP Lesson 12 Knowledge and Skills Nugget 3
PMI-ACP Lesson 12 Knowledge and Skills Nugget 3PMI-ACP Lesson 12 Knowledge and Skills Nugget 3
PMI-ACP Lesson 12 Knowledge and Skills Nugget 3
 
PMI-ACP Lesson 12 Knowledge and Skills Nugget 2
PMI-ACP Lesson 12 Knowledge and Skills Nugget 2PMI-ACP Lesson 12 Knowledge and Skills Nugget 2
PMI-ACP Lesson 12 Knowledge and Skills Nugget 2
 
PMI-ACP Lesson 12 Knowledge and Skills Nugget 1
PMI-ACP Lesson 12 Knowledge and Skills Nugget 1PMI-ACP Lesson 12 Knowledge and Skills Nugget 1
PMI-ACP Lesson 12 Knowledge and Skills Nugget 1
 
PMI-ACP Lesson 11 Agile Value Stream Analysis
PMI-ACP Lesson 11 Agile Value Stream AnalysisPMI-ACP Lesson 11 Agile Value Stream Analysis
PMI-ACP Lesson 11 Agile Value Stream Analysis
 
PMI-ACP Lesson 10 Agile Metrics
PMI-ACP Lesson 10 Agile MetricsPMI-ACP Lesson 10 Agile Metrics
PMI-ACP Lesson 10 Agile Metrics
 
PMI-ACP Lesson 9 Agile Risk Management
PMI-ACP Lesson 9 Agile Risk ManagementPMI-ACP Lesson 9 Agile Risk Management
PMI-ACP Lesson 9 Agile Risk Management
 

Dernier

Dernier (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 

GoF J2EE Design Patterns

  • 1. @Diego  Thanh  Nguyen  -­‐  http://free.smartbiz.vn   J2EE  DESIGN  PATTERN   10/8/12   www.smartbiz.vn   1  
  • 2. Table  Of  Content   q I.  GoF  Design  Pattern   v I.1.  Creation  Patterns   v I.2.  Structural  Patterns   v I.3.  Behavioral  Patterns   q II.  J2EE  Presentation:     q III.  J2EE  Business:     q IV.  J2EE  Integration   10/8/12   www.smartbiz.vn   2  
  • 3. I.  How  Design  Patterns  Arise  ?   Pattern  1.   Context Problem   a design situation giving rise to a design problem   Problem a set of forces occuring in that context Solution 2.  Context   a form or rule that can be applied to resolve these forces Forces   IF    you  Nind  yourself  in  CONTEXT   3.                              for  example  EXAMPLES,   Solution                              with  PROBLEM,                                entailing  FORCES   THEN    for  some  REASONS,                              apply  DESIGN  FORM  AND/OR  RULE   BeneFits   Consequences                              to  construct  SOLUTION   Related  Patterns                              leading  to  NEW  CONTEXT  &  OTHER  PATTERNS   10/8/12   www.smartbiz.vn   3  
  • 4. I.  Design-­‐Pattern  Catalog   ! ! Purpose! Creational! Structural! Behavioral! Class! • Factory!Method! • Adapter! • Interperter! • Singleton! • Façade! • Observer! • Factory! • Decorator! • Command! • Abstract!Factory! • Composite! • Iterator! Scope! • Builder! • Adapter! • Chain!of!Responsibility! Object! • Prototype! • Bridge! • Mediator! • Object!Pool! • Flyweight! • Momento! • Proxy! • State! • Strategy! • Visitor! ! ! Defer  object  creation  to     Describe  algorithms  and     another  object   Nlow  control   Describe  ways  to     assemble  objects   10/8/12   www.smartbiz.vn   4  
  • 5. I.1.  Creation  Patterns   q Creational  Patterns    prescribe  the  way   that  objects  are  created.  These  patterns  are   used  when  a  decision  must  be  made  at  the   time  a  class  is  instantiated.     q Singleton:  ensure  a  class  has  one  Instance,   and  provide  a  global  point  of  access  to  it.   q Abstract  Factory:  provide  an  interface  for   creating  families  of  related  or  dependent   objects  without  specifying  their  concrete   classes.   10/8/12   www.smartbiz.vn   5  
  • 6. I.1.1  Abstract  Factory   q  Intent:  create  families  of  related  objects  without   specifying  subclass  names   q  Applicability:  when  clients  cannot  anticipate   groups  of  classes  to  instantiate   q  Concrete  factories  create  groups  of  strategies     10/8/12   www.smartbiz.vn   6  
  • 7. I.2.  Structural  Patterns   q Structural  Patterns    prescribe  the   organization  of  classes  and  objects.   q Adapter   v   Convert  the  interface  of  a  class  into  another   interface  that  clients  expect   v   Adapter  lets  classes  work  together  that  couldn’t   otherwise  because  of  incompatible  interfaces   q Decorator   v   Extend  the  functionality  of  the  original  class  in  a   way  that  is  transparent  to  the  client  class   10/8/12   www.smartbiz.vn   7  
  • 8. I.2.1.  Composite   q Intent   v treat  individual  objects  &  multiple,  recursively-­‐ composed  objects  uniformly   q Applicability   v Objects  must  be  composed  recursively,   v and  no  distinction  between  individual  &  composed   elements,   v and  objects  in  structure   can  be  treated  uniformly   10/8/12   www.smartbiz.vn   8  
  • 9. I.2.1.  Composite   q CORBA  Naming  Service  example  using   CosNaming::BindingIterator  (which  is  an   example  of  the  “Batch  Iterator”  pattern   compound  from  POSA5)   Composite   Node   Leaf  Node   10/8/12   www.smartbiz.vn   9  
  • 10. I.3.  Behavioral  Patterns   q Behavioral Patterns prescribe the way objects interact with each other. They help make complex behavior manageable by specifying the responsibilities of objects and the ways they communicate with each other. q State:  allow  an  object  to  alter  its  behavior   when  its  internal  state  changes   10/8/12   www.smartbiz.vn   10  
  • 11. I.3.1.  Strategy   q Intent   v  deNine  a  family  of  algorithms,  encapsulate  each  one,  &   make  them   v  interchangeable  to  let  clients  &  algorithms  vary   independently   q Applicability   v  When  object  is  conNigurable  with  one  of  many  algorithms,   v  and  all  algorithms  can  be  encapsulated,   v  and  one  interface  covers  all  encapsulations     10/8/12   www.smartbiz.vn   11  
  • 12. I.3.1.  Strategy   q Strategy  applied  in  distributed  (middleware)   Hook  for   marshaling   Hook  for   strategy   the  request   demuxing   Hook  for  the  event   strategy   demuxing  strategy   Hook  for  the   Hook  for  the   connection   concurrency   management   strategy   strategy   Hook  for  the   underlying   transport   strategy   10/8/12   www.smartbiz.vn   12  
  • 13. I.3.1.  Oracle  Fusion  Component   OracleFusion Groupware API: A unified interface for all connectors that access the groupware servers via WebDAV, applying Singleton, Façade and Factory design patterns All connectors utilize the Jakarta EnterConnect Groupware API Jackrabbit (client-side) API to send requests to and receive Exchange OpenGroupware Lotus Domino responses from a variety of Connector Connector Connector WebDAV-enabled groupware servers MS Exchange 2003 Email Jakarta Slide API WebDAV Server XML HTTP request Calendar Jakarta Commons HTTP Client JDOM (JSR 102) Contact XML HTTP response Jakarta Commons Logging Java Transaction API Task Uploaded Document Jakarta Jackrabbit re-uses some of open source libraries such as the Jakarta Commons library (HTTP Client &Logging), JDOM (JSR 102), JTA, JMX, … 13  
  • 14. I.3.2.  OF  Design  Pattern   q Singleton:  the  Connector  class  must  only  have  one  instance  because  it’s  wasteful  &   useless  to  keep  several  instances  on  memory.  Keeping  so  many  connectors  will  difNicult   to  manage  lifecycle  &  impact  the  performance  of  application.   q Factory  Method:  because  of  we  assume  our  API  can  be  used  against  multiple  servers   so   that   there   must   be   a   Connector   for   each   server   (i.e.   ECExchangeConnector,   ECLotusDominoConnector,   ECOpenGroupwareConnector).   Each   connector   is   responsible   for   manufacturing   its   own   managers   (MailManager,   CalendarManager,   TasksManager)  and  delegate  the  jobs  to  them.  The  connector  will  only  be  determined   by  the  client  depending  on  the  conNiguration.   v For   example,   if   a   client   (portlet)   need   to   send   a   mail   by   Exchange   server   then   it   will   call   the   ECExchangeConnector;   this   connector   then   will   use   its   localized   manager   ExchangeMailManager  to  make  life  easier.   q Abstract  Factory:  ECGroupwareFactory  is  the  abstract  factory  class  for  all  connectors   because  it  will  expose  a  uniFied  interface  for  connectors  to  client.   q Facade:   the   uniFied   interface   will   be   deFined   in   the   Façade   pattern.   As   stated   before,   a   speciNic   Connector   will   delegate   the   appropriate   jobs   to   its   subsystems   (managers).  The  façade  pattern  also  decouples  the  managers  from  the  client  and  other   managers,  thereby  promoting  independence  and  portability.   10/8/12   www.smartbiz.vn   14  
  • 15. I.3.1.  OF  Design  Pattern   <<Factory Method>> «interface» TasksManager <<Abstract Factory>> ECGroupwareFactory <<Façade>> ExchangeTasksManager <<Singleton>> ECLotusDominoConnector ECOpenGroupwareConnector ECExchangeConnector ExchangeCalendarManager ExchangMailManager «interface» «interface» MailManager CalendarManager Apache Slide Class 15   10/8/12   www.smartbiz.vn  
  • 16. I.4.1.  Observer  Pattern   q Easier  to  keep  a  consistent  and  maintainable   view  of  the  data   v Half  as  many  connections  between  actions,  views   v Views  are  independent  and  unaware  of  each  other   Data   Action   Action   Action   Action   Action   Action   Action   Action   View  à    View  &  Action  à     Data  notiNies  observers  via  events   View  Messages  about  the  data   when  the  state  of  the  data  changes   10/8/12   www.smartbiz.vn   16  
  • 17. I.4.2.  Implementing  an  Observer   1.  Assign  the  subject  to  the   observers  (MainForm_Load)       IssueSubject         10/8/12   www.smartbiz.vn   17  
  • 18. I.4.3.  Implementing  an  Observer   1.  Assign the subject to the observers (MainForm_Load) m_subject = new IssueSubject() paneA.Subject = m_subject b paneB.Subject = m_subject ... c d a IssueSubject 10/8/12   www.smartbiz.vn   18  
  • 19. I.4.4.  Implementing  an  Observer   1.  Assign the subject to the observers (MainForm_Load) m_subject = new IssueSubject() paneA.Subject = m_subject b paneB.Subject = m_subject ... c d 2.  Observers bind and save changes to Subject.DataSet a IssueSubject 10/8/12   www.smartbiz.vn   19  
  • 20. I.4.5.  Implementing  an  Observer   1.  Assign  the  subject  to  the   observers  (MainForm_Load)   m_subject  =  new  IssueSubject()   paneA.Subject  =  m_subject   paneB.Subject  =  m_subject  ...   b     c   d   2.  Observers  bind  and  save   changes  to  Subject.DataSet   a   3.  When  data  changes,  subject     raises  DataChanged  event     IssueSubject         10/8/12   www.smartbiz.vn   20  
  • 21. I.4.6.  Implementing  an  Observer   1.  Assign  the  subject  to  the   observers  (MainForm_Load)   m_subject  =  new  IssueSubject()   paneA.Subject  =  m_subject   b   paneB.Subject  =  m_subject  ...   c   d   2.  Observers  bind  and  save   changes  to  Subject.DataSet   a   3.  When  data  changes,  subject     raises  DataChanged  event         4.  Observers  handle  subject     events  to  rebind  data,  if   IssueSubject   they  care       m_subject.DataChanged  +=  …     ‘  rebind     10/8/12   www.smartbiz.vn   21  
  • 22. I.5.1.  Coordinate  Command  State   q Related  menu  and  toolbar  widgets  are  not   automatically  handled  together   q Command  Pattern   v  Command  objects  unify  the  state  and  action  for  related   UI  widgets     q Example:   v “Save”  action   Ø  Menu  item   Ø  Toolbar  button   Ø  Context  menu     10/8/12   www.smartbiz.vn   22  
  • 23. I.5.2.  Implementing  a  Command   1.  Create  a  Command  for  each  action  in  MainForm_Load()   action  =  new  Command.Action(this.WorkOfNline_Action)   ofNlineCommand  =  new  Command(action)   2.  Wire  menu  items  and  toolbar  buttons  to  the  Command   using  Commander  objects   MenuItemCommander.Connect(menuWorkOfNline,  ofFlineCommand  )   ToolBarButtonCommander.Connect(tlbOfNline,  ofFlineCommand  )      3.  Control  button  and  menu  item  state  through  the   Command   '  Disable  all  UI  widgets  connected  to  this  command   ofNlineCommand.IsEnabled  =  false   10/8/12   www.smartbiz.vn   23  
  • 24. I.6.1.  Accelerated  J2EE  Development   q Architect  Service-­‐Oriented  Components   v  Design  for  Flexible,  Agile  Applications  and     Iterative  Development   q Apply/Extend  Pre-­‐Built  COTS  Components   v  Infrastructure  and  Common  Business  Components   q Generate/Extend  Custom  Components   v  Rapidly  Specify  and  Provision  New  Components   q Leverage  Industry  Development  Standards   v  Frameworks  (STRUTS,  Spring  /  Weld,  Hibernate)   v  Patterns  (MVC)   v  XML,  Best  Practices   10/8/12   www.smartbiz.vn   24  
  • 25. II.  J2EE  Application  Design  Patterns   Business  Logic  &   Data  Integration   Presentation   Messaging  Fabric   &  Persistence   EJB  Container   EJB  Container   Response   8.   Execute   Business   Resources   Biz  Method   13.   Request   Service   14.   CRUD   Facade   10b.   Data   Data   Query   9.   Get/Set   Access   Database   <<de-­‐serialize>>   Web  Server  &   18.  Response   Assemble   Remove   Object   Serialized   RMI   JMS   Servlet  Engine   Value   Data   Directory   Object   16.  Forward   JSF,  JSP   JMS   (Taglibs)   <<creates>>   Value   12.   1.  Request   Object   Get/Set   17.  State?   Assembler   <<uses>>   Action   Remove   Data   Servlet   10a.   Access   <<uses>>   Invoke   Proxy   4.  Dispatch   2.  Fill  State   Data   XML   11.   Entity   Connection   3.  Validate   CRUD   Connection   Action  to   Bean     Pool   (Stateless)   Data   Factory   Form    &   Value   Session   Forward   <<uses>>   Object   Bean   Mappings   Action   Form   5.  Get  Delegate   Action   Object   15.  Fill  State   <<uses>>   Key   Other  Infrastructure   6.  Execute     <<supplies>>   RMI   Business   Business   <<uses>>   EJB  Container Value   Model   Delegate   Delegate   M   JMS   Object   Pattern   Factory   Adapter   7a.   Event   Security   Messaging   Event   Execute   View   Interceptor   Management   Command   NotiFication   Biz  Method   Business   V   Pattern   Framework   Framework   Factory   Framework   Service   Proxy   <<uses>>   Controller   C   Pattern   <<uses>>   7b.  CRUD  Data   Data   Message  Q   Filter   Service   Access   &  Channel   Other   Interceptors   Activation   Proxy   To  DAO   P   Pattern   Locator   10/8/12   www.smartbiz.vn   25  
  • 26. II.  Model-­‐View-­‐Controller  –  Passive   :Controller :Model :View handleEvent service update getData 10/8/12   www.smartbiz.vn   26  
  • 27. II.  Model-­‐View-­‐Controller  –  Active   Controller <<interface>> Observer Model +update() View :Model :View handleEvent notify update getData data 10/8/12   www.smartbiz.vn   27  
  • 28. II.1.  Presentation  Tier  Patterns   q Intercepting  Filter   q Front  Controller:  Use  of  a  Controller  to   handle  all  web  requests   q Dispatcher  View:  The  controller  works  with   a  Dispatcher  that  handles  navigation   q Composite  View   q View  Helper   q Service  to  Worker   10/8/12   www.smartbiz.vn   28  
  • 29. II.2.  Intercepting  Filter   q Problems:   v Verify  authentication   v Check  type  of  client   v Is  the  session  valid?       q Solution:  implement  one  or  more   Intercepting  Nilters.   q Sample:  Filter-­‐servlet  -­‐  can  transparently   pre  and  post  process  all  requests  in  an   unlimited  length  Nilter  chain.   10/8/12   www.smartbiz.vn   29  
  • 30. II.3.  Front  Controller  &  Dispatcher   q Front  Controller  -­‐  Problems:   v Multiple  views.   v Navigation  logic  embedded  in  views.   v DifNicult  to  maintain  view  logic  as  application   grows.   v Want  to  reuse  view  navigation  within  multiple   clients.   10/8/12   www.smartbiz.vn   30  
  • 31. II.3.  Front  Controller  -­‐  Dispatcher   Client FrontController Dispatcher Vi ew Helper 1: Send Request 1.1: Delegate Request 1.1.1: Forward Request 2: Send Request 2.1: Forward Request 3: Send Request 3.1: Process Request 10/8/12   www.smartbiz.vn   31  
  • 32. III.4.  View  Helper   q Problem:   v Many  common  operations  in  each  view.   v Often  view  output  is  dependant  on  business   data.   v Create  more  cohesive  look  and  feel.   v Like  to  hand  off  UI  to  web  design  group   q Solution:   v Basically  anything  that  helps  you  display  your   model  data  in  a  reusable  fashion.   v Implemented  as  JavaBeans,  Tags  or  XML/XSLT   q See  the  JSTL,  JSF  and  Struts.   10/8/12   www.smartbiz.vn   32  
  • 33. II.5.  Composite  View   q Problem:   v Many  common  &  recurring  components  in  a  view.     v Fragments  may  display  differently  given  user  type   (i.e.  faculty,  student).   v Look  and  feel  in  Nlux  needs  to  be  easily   updateable.   q Differs  from  View  Helper  as  the  Composite   View  decides  which  sub-­‐views  to  include   while  View  Helper  generally  decides  how  to   display  a  given  sub-­‐view.   10/8/12   www.smartbiz.vn   33  
  • 34. III.  Business  Tier  Patterns   q  Business  Delegate:  use  of  a  Business  Delegate  to   hide  Implementation  Detail.   q Session  Façade   q Service  Locator   q Value  Object   q Composite  Entity   q Value  Object  Assembler   q Value  List  Handler   10/8/12   www.smartbiz.vn   34  
  • 35. III.1.  Business  Delegate   Cl ient BusinessService 1: Creat e wi th ID BusinessDelegate 1.1: Convert ID to Handle Handle 1.1.1: Create 2: Invoke 2.1: Get Business Service 2.1. 1: Connect 2.1. 2: Return Business Service 2.2: Invoke 10/8/12   www.smartbiz.vn   35  
  • 36. III.2.  Session  Façade  Pattern   q Problem:   v Need  very  loose  coupling  between  client  and   ever  changing  business  tier.   v Data  tier  changing;  need  to  improve  reuse.   q Session  Bean     EJB Tier provides  uniNied  approach   q Façade  hides     Entity  Bean  Details   Session Client Entity Bean Bean 10/8/12   www.smartbiz.vn   36  
  • 37. IV.  Integration   q Data  Access  Object   q Service  Activator   q User  WorkNlow  Integrator   10/8/12   www.smartbiz.vn   37  
  • 38. IV.1.  Data  Access  Object   Business DataAcces accesses Object sObject inherits inherits inherits Oracle Sybase DB2DAO DAO DAO adapts adapts adapts Oracle DB2 Sybase Database Database Database 10/8/12   www.smartbiz.vn   38  
  • 39. 10/8/12   www.smartbiz.vn   39