SlideShare une entreprise Scribd logo
1  sur  62
Télécharger pour lire hors ligne
LibrePlan architecture
     An overview




Javier Morán Rúa <jmoran@igalia.com>
            October 2012
Software architecture

                     What is it ?
 The software architecture of a program or computing
  system is the structure or structures of the system,
which comprise software elements, the externally visible
  properties of those elements, and the relationships
                     among them.




                                       www.libreplan.com
Software architecture

●   Considerations about architecture:
    ●   Impressive-sounding word. To talk about something is
        important.
    ●   Many definitions. Not an agreement.
    ●   Three key ideas:
        –   High level design
        –   Difficult to change
        –   Many architectures in one system
                                           www.libreplan.com
Architectural patterns

●   Definition: Description of elements and relation types
    together with a set of constraints on how they may be
    used.
●   Some traits:
    ●   They guide how to implement new features.
    ●   They exhibit known quality attributes.



                                           www.libreplan.com
Layering pattern

●   Layering: It is a technique to deal with complexity.
●   Several layers of software (source code) like in a
    cake.
    ●   Each layer rests on a lower layer.
    ●   The lower layer is unaware of the upper layer




                                             www.libreplan.com
Layering pattern

●   Benefits:
    ●   You can understand each layer in isolation.
    ●   You can substitute each layer by an alternative
        implementation.
    ●   They promote reuse.
    ●   They minimize dependencies between structural
        parts.

                                          www.libreplan.com
Layering pattern

●   Downsides:
    ●   Two much layers can harm performance.
    ●   Desired encapsulation many times is imperfect.
        Cascade changes.




                                        www.libreplan.com
Layering pattern

●   LibrePlan architecture uses the layering pattern.
●   LibrePlan is a three layer (tier) application.
    ●   Layer 0.
        –   Purpose = Persistence
        –   Components = Hibernate framework +
            Repositories.



                                           www.libreplan.com
Layering pattern

●   Layer 1.
    –   Purpose = Domain logic
    –   Components = Domain Entities, Behavioral
        classes, Conversational services
●   Layer 2.
    –   Purpose = Interfaces (Human + Machine)
    –   Components = ZK web pages, Web services.


                                           www.libreplan.com
Client - server pattern

●   Definition: A program is a client-server application if
    is a piece of software which runs split it two
    machines.
       –   Client computer. It makes request to a remote
           server computer.
       –   Server computer. It does the calculations asked
           by clients and answers them.


                                           www.libreplan.com
Client - server pattern

●   Some features:
    ●   It implies the existence of a network.
    ●   Client-server applications can be cross-platform.
    ●   Some nodes can be clients and servers at the same
        time depending on the analyzed role.
    ●   They are related with the layering. Where do you run
        the layers?


                                             www.libreplan.com
Client - server pattern

●   LibrePlan is a client-server application.
●   LibrePlan clients:
    ●   User browser.

        –   Example: Firefox, Google chrome.
        –   Runs part of the interface tier.
    ●   Outer WS client. Example: ERP importing into LibrePlan
        employees.
    ●   LibrePlan WS client. Example: outsourcing module
    ●   LibrePlan persistence tier. Its server is the RDMS.
                                                  www.libreplan.com
Client - server pattern

●   LibrePlan server.
    ●   Runs part of the ZK interface tier, the domain logic
        and part of the persitence layer.




                                            www.libreplan.com
Domain model pattern

●   What is the domain? Subject area to which the user
    applies the program.
    ●   LibrePlan domain is project planning, monitoring
        and control.
●   In a few words: Build a model of the domain that both
    incorporates logic and data.
●   What implies? Inserting a whole layer of objects.


                                         www.libreplan.com
Domain model pattern

●   Alternative pattern (more frequently used):
    Transaction script.
●   It what does it consist of? It organizes business logic
    by procedures where each procedure handles a
    single request from the presentation.




                                            www.libreplan.com
Domain model pattern

●   Advantages:
    ●   It allows logic reuse on large systems. Typical
        transaction script architectures promote duplication
    ●   It allows to change easily the behavior of complex
        domains. It uses the power of the OO model to
        accomplish it.
    ●   It can be used for knowledge crunching (analysis)
        with domain experts. Domain driven design.
                                           www.libreplan.com
Domain model pattern

●   Downsides:
    ●   It requires effort. Assimilate the paradigm shift.
    ●   It requires initially more effort to implement.
●   LibrePlan uses domain model pattern.
●   How is it implemented?
    ●   Hibernate entities are related each other.
    ●   They are POJOs. They can live outside the Hibernate
        session.
                                               www.libreplan.com
IoC pattern
●   Inversion of Control – Pattern of object-oriented
    programming where the object coupling is done at run
    time by an assembler object and is typically not known
    at compile time by static analysis.
●   How is done in traditional programming?
    ●   The flow and the business logic is determined by
        objects that are statically assigned to one another.



                                           www.libreplan.com
IoC pattern
●   Benefits:
    ●   Decouples the execution of some tasks from
        specific implementation. It allows to replace
        components.
    ●   It allows to reuse components more easily (among
        different programs).
    ●   It allows to focus the components in what they are
        designed for (cohesion).

                                           www.libreplan.com
IoC pattern
●   Techniques to implement Inversion of Control
    ●   Factory method pattern (GoF).




                                        www.libreplan.com
IoC pattern
●   Using a Service Locator.
    –   An object who knows how to get hold of all the
        possible services an application can need.
    –   The client component makes explicit calls to the
        Service Locator
●   Using Dependency Injection.




                                       www.libreplan.com
DI pattern
●   Concept: Software design pattern where an
    element, the injector, places dependent elements to
    the destination according to the destination
    requirements.
●   Three elements:
    –   A dependent consumer.
    –   A declaration of a component's dependencies.
    –   An injector (aka container or provider)
                                       www.libreplan.com
DI pattern
●   Three types of DI:
    –   Interface injection. The dependent component provides
        an interface that the consumer must implement in order
        to get the dependencies at run time.
    –   Setter injection. The dependent consumer exposes a
        setter method that the injector uses.
    –   Constructor injection. The dependencies are placed in the
        constructor of the dependent consumer.



                                                www.libreplan.com
IoC - DI LibrePlan
●   LibrePlan uses Inversion of Control.
●   LibrePlan implements Inversion of Control with the
    pattern Dependency Injection.
●   LibrePlan uses the Setter Dependency Injection Type.
●   LibrePlan uses Spring framework as injector
    (container)




                                       www.libreplan.com
IoC – DI LibrePlan
●   Spring Framework has about 20 modules.
    ●   Core Container.
    ●   Inside the Core Container the module for IoC and DI
        is the Core and Beans.
●   Where is it used IoC in LibrePlan architecture?
    ●   Getting models from ZK page controllers.
    ●   Getting repositories (DAO) from models.


                                         www.libreplan.com
MVC pattern
●   Model-View-Controller: It is a presentation pattern that
    consists of splitting the user interface interaction in
    three roles (Model, View and Controller)
●   Model Role. Non-visual object containing all the
    information and behavior from the application domain.
●   View Role. Represents the display of the model in the
    UI. Example: UI widgets or HTML. It only displays
    information.

                                           www.libreplan.com
MVC pattern
●   Controller Role. It takes the user input, manipulates
    the model and causes the view to update accordingly.




                                         www.libreplan.com
MVC pattern
●   Two separations:
    ●   Presentation from the model
    ●   Controller from the view
●   Reasons separation presentation from model:
    ●   They are different concerns.
    ●   Depending on context you can use model in different ways.
    ●   Non visual objects are easier to test than visual ones



                                               www.libreplan.com
MVC pattern
●   Separation controller from the view:
    ●   Less important separation.
    ●   This separation is usually not done.
●   LibrePlan uses MVC pattern:
    ●   It does not separate controller from view. Many times in the
        controller is rendered the view (HTML).
    ●   View and the controller split:
        –   Some part runs in the client browser (HTML + JS)
        –   Other part runs in the server (Java objects).
                                                  www.libreplan.com
MVC pattern
●   LibrePlan uses the MVC pattern
    ●   The models are injected (DI) with the Spring
        container into the controllers.
    ●   The models belong to the domain layer and are
        decoupled by DI from the presentation layer.
    ●   The models are reused sometimes:
        –   HTML view
        –   Web Services
                                          www.libreplan.com
ZK architecture
●   Component based framework.
    ●   It abstracts widgets that are reused in different web
        pages. Other: Tapestry, Wicket
●   Components have two representations:
    ●   DOM in the browser.
    ●   Java objects in the server (POJOs)
●   They are synchronized automatically by ZK


                                           www.libreplan.com
ZK architecture




        www.libreplan.com
ZK architecture
●   It is a RIA framework
●   Very productive.
    ●   You do not need to program in JS.
    ●   You have not to worry about AJAX for
        synchronization.
●   The best place to manage complex business logic is
    the server. With ZK you have the domain accessible
    from the presentation easily.
                                        www.libreplan.com
LibrePlan and ZK
●   LibrePlan uses ZK for the web interface.
●   LibrePlan uses the components of ZK CE.
●   LibrePlan has developed new ZK components mainly
    related with the Gantt chart. Examples:
    ●   Task component.
    ●   Dependency component
    ●   Milestone component
    ●   Timetracker component
                                         www.libreplan.com
Object relational mapping
●   Object relational mapping is a technique used for
    converting the data in a relational database to the
    object oriented paradigm.
●   Hibernate is Java ORM that is the de facto standard in
    the Java platform for persistence.
●   LibrePlan uses Hibernate as ORM in the persistence
    layer.



                                         www.libreplan.com
Layers data exchange
●   What is an entity?
    ●   An entity is an object defined primarily by its
        identification.
    ●   It is anything that has continuity through a life-cycle
        and distinction independent of the attributes that are
        important for the application's user. Example:
        Person, city, lottery ticket, etc.



                                             www.libreplan.com
Repository pattern
●   A repository represents all objects of a certain type as
    a conceptual set.
    ●   Collection with a more elaborate querying capability.
●   Clients requests objects from the repository using
    query methods based on criteria specified by the
    client.
●   Repository retrieves the requested objects,
    encapsulating the machinery of database queries.

                                          www.libreplan.com
Repository pattern
●   LibrePlan uses the repository pattern.
    ●   They are Java classes called XXXDAO
    ●   They are implemented with Hibernate (HQL, Criteria API).
●   They are managed by DI with the Spring container.
    ●   They are injected in the domain Model classes (used in the
        MVC presentation pattern)
    ●   They are used also in the domain entities but cannot be injected
        there. They are got from a Registry where they are injected.



                                                  www.libreplan.com
Repository pattern
●   In LibrePlan entities are loaded in memory by two
    ways:
    ●   Using the repositories.
    ●   By traversing the entity relationships. Two
        conditions:
        –   Hibernate session has to be open.
        –   Objects must be attached.


                                           www.libreplan.com
Layers data exchange
●   Bottom layers offer services to the upper layers by
    returning data.
●   There are two approaches to exchange data between
    subsystems: Use Data Transfer Objects or return the
    own data objects of the bottom layer.
●   Data Transfer Objects.
    ●   They do not have behavior.
    ●   Only getters and setters.
                                         www.libreplan.com
Layers data exchange
●   Data Transfer Objects:
    ●   They are designed according to client needs.
    ●   Usually aggregate data from several classes of the
        subsystem that is returning them.
●   Analyzing DTOs:
    ●   They are expensive and time-consuming because of
        the translation code (in - out)


                                            www.libreplan.com
Layers data exchange
●   Analyzing DTOs:
    ●   They are recommendable if the data objects of the
        service subsystem have inner dependencies. Most
        of all, for network communications.
    ●   They are comfortable and easy to use by the clients
        because they are prepared for them.




                                          www.libreplan.com
Layers data exchange
●   LibrePlan use of DTOs in:
    ●   Web services. They are easily converted in XML to be
        send in the web services body with JAXB (Java
        Architecture for XML Binding).
    ●   Reports done with JasperReports. The reports require
        to receive DTOs because of the framework internals.
●   LibrePlan uses the domain objects (entities) as layer
    data exchange.

                                          www.libreplan.com
Layers data exchange
●   Perils of using domain entities (Hibernate mapping
    objects) as exchange data: Beware of the life cycle.




                                        www.libreplan.com
Layers data exchange
●   Perils of using domain entities (Hibernate mapping
    objects) as data exchange: Being aware of the graph
    depth of the objects retrieved.
    ●   You cannot retrieve the full database (performance
        issues).
    ●   The client has to know the extent of the graph
        retrieved. If not, LazyInitializationException maybe is
        thrown.

                                           www.libreplan.com
Conversations
●   LibrePlan is an stateful system.
    ●   Stateless system. At any point the output only depends on
        the input.
    ●   Stateful system. At a point in time the output depends on
        the input and internal state.
●   You cannot keep the transaction open between user
    interactions.
    ●   They take a long time and consume resources.
    ●   Maybe they do not finish.
                                              www.libreplan.com
Conversations
●   Conversations are designed in LibrePlan with the
    pattern session-per-request-with-detached-objects.




                                       www.libreplan.com
Conversations
●   Things to take into account with conversations with
    detached objects:
    ●   Beware of reattaching objects on asking operations
        from the controller.
    ●   Avoid having duplicated objects in the session.




                                          www.libreplan.com
Conversations
●   In LibrePlan session-per-request-with-detached
    objects conversations:
    ●   They happen in the XXXModel objects.
    ●   Model objects are injected by DI in the ZK UI
        controllers.
    ●   They have prototype scope (not singleton).
        –   The dependent object (XXXModel) is created by
            Spring before its injection.
                                           www.libreplan.com
Conversations
●   In LibrePlan session-per-request-with-detached
    objects conversations:
    ●   There is a convention for the conversations:
        –   prepareForOperation()
        –   confirmOperation()




                                          www.libreplan.com
OCC Pattern
●   OCC (Optimistic Concurrency Control) is a pattern
    that assumes that everything will be OK and that
    conflicting data modifications are rare.
●   OCC raises an error only at the end of a unit of work,
    when data is written.
●   It sets the strategy: First commit wins.




                                          www.libreplan.com
OCC Pattern




      www.libreplan.com
OCC Pattern
●   LibrePlan uses OCC.
●   It is got help of Hibernate.
    ●   A version field is used, which is incremented each
        new update operation.




                                          www.libreplan.com
Aggregate Pattern
●   Problem: In a complex domain it is difficult to
    guarantee the consistency of changes to objects with
    complex associations.
    ●   Invariants needs to be maintained in a closed group
        of objects, not just discrete objects.
●   Use the aggregate pattern: An aggregate is a cluster of
    assocated objects that is treated as a unit for data
    change operations.

                                            www.libreplan.com
Aggregate Pattern
●   The definition of an aggregate implies:
    ●   To define a boundary.
        –   Defines what is inside the aggregate
    ●   To define the root of the aggregate.
        –   It is a simple specific entity contained in the
            aggregate




                                              www.libreplan.com
Aggregate Pattern
●   Rules of the pattern:
    ●   The entities outside the aggregate only can hold
        references to the root aggregate.
    ●   Objects inside the root aggregate can hold
        references to each other.
    ●   Aggregates root can be got directly with
        repositories. All other objects must be found by
        traversal of associations.

                                            www.libreplan.com
Aggregate Pattern
●   Rules of the pattern:
    ●   A delete operation must erase everything inside the
        aggregate.
●   LibrePlan uses Aggregate pattern.
    ●   The XXXModel need to be aware of the aggregates.




                                         www.libreplan.com
Aggregate Pattern
●   Example of aggregate in LibrePlan




                                        www.libreplan.com
Domain Model Validation
●   Problem: Many applications implement validations in
    many layers. This has two drawbacks:
    ●   Duplication.
    ●   You may not be aware on the validation code you
        have implement if the application is large.




                                           www.libreplan.com
Domain Model Validation
●   Custom validation scheme:




                                www.libreplan.com
Domain Model Validation
●   Domain Model Validation in entities: It consists of
    implementing the validation logic inside domain model
    entities.




                                          www.libreplan.com
Domain Model Validation
●   LibrePlan uses validation inside domain model
    entities.
●   LibrePlan uses Hibernate Validator to do this process
    simpler.




                                       www.libreplan.com

Contenu connexe

En vedette

]project-open[ Screenshots
]project-open[ Screenshots ]project-open[ Screenshots
]project-open[ Screenshots Klaus Hofeditz
 
Documentación de LibrePlan Audiovisual (castellano)
Documentación de LibrePlan Audiovisual (castellano)Documentación de LibrePlan Audiovisual (castellano)
Documentación de LibrePlan Audiovisual (castellano)LibrePlan Open Web Planning
 
]project-open[ on Amazon AWS
]project-open[ on Amazon AWS]project-open[ on Amazon AWS
]project-open[ on Amazon AWSKlaus Hofeditz
 
Software engineering project management
Software engineering project managementSoftware engineering project management
Software engineering project managementjhudyne
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]Kuro Hsu
 

En vedette (8)

LibrePlan Audiovisual documentation
LibrePlan Audiovisual documentationLibrePlan Audiovisual documentation
LibrePlan Audiovisual documentation
 
]project-open[ Screenshots
]project-open[ Screenshots ]project-open[ Screenshots
]project-open[ Screenshots
 
NavalPlan Talk at LinuxTag 2011
NavalPlan Talk at LinuxTag 2011NavalPlan Talk at LinuxTag 2011
NavalPlan Talk at LinuxTag 2011
 
Documentación de LibrePlan Audiovisual (castellano)
Documentación de LibrePlan Audiovisual (castellano)Documentación de LibrePlan Audiovisual (castellano)
Documentación de LibrePlan Audiovisual (castellano)
 
Presentacion libreplan LSWC 2012
Presentacion libreplan LSWC 2012Presentacion libreplan LSWC 2012
Presentacion libreplan LSWC 2012
 
]project-open[ on Amazon AWS
]project-open[ on Amazon AWS]project-open[ on Amazon AWS
]project-open[ on Amazon AWS
 
Software engineering project management
Software engineering project managementSoftware engineering project management
Software engineering project management
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
 

Similaire à Libreplan architecture

Feature Development with jQuery
Feature Development with jQueryFeature Development with jQuery
Feature Development with jQueryMichael Edwards
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice frameworkFabrice Sznajderman
 
Android Modularization
Android ModularizationAndroid Modularization
Android ModularizationYoung-Hyuk Yoo
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examplesAbdii Rashid
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCUlrich Krause
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminarGal Marder
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and PatternsFRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and PatternsLeapfrog Technology Inc.
 
Liferay portals in real projects
Liferay portals  in real projectsLiferay portals  in real projects
Liferay portals in real projectsIBACZ
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesUlrich Krause
 
Angular vs. polymer a face off for the throne of frontend development
Angular vs. polymer  a face off for the throne of frontend developmentAngular vs. polymer  a face off for the throne of frontend development
Angular vs. polymer a face off for the throne of frontend developmentMoon Technolabs Pvt. Ltd.
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 
Essential Software Architecture - Chapter 1 Understanding Software Architectu...
Essential Software Architecture - Chapter 1 Understanding Software Architectu...Essential Software Architecture - Chapter 1 Understanding Software Architectu...
Essential Software Architecture - Chapter 1 Understanding Software Architectu...John Ortiz
 
Foster - Getting started with Angular
Foster - Getting started with AngularFoster - Getting started with Angular
Foster - Getting started with AngularMukundSonaiya1
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Fwdays
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29Nitin Bhojwani
 
[Android] DI in multimodule application
[Android] DI in multimodule application[Android] DI in multimodule application
[Android] DI in multimodule applicationOleg Mazhukin
 
Programming for non tech entrepreneurs
Programming for non tech entrepreneursProgramming for non tech entrepreneurs
Programming for non tech entrepreneursRodrigo Gil
 

Similaire à Libreplan architecture (20)

Feature Development with jQuery
Feature Development with jQueryFeature Development with jQuery
Feature Development with jQuery
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
Android Modularization
Android ModularizationAndroid Modularization
Android Modularization
 
Angular 2
Angular 2Angular 2
Angular 2
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and PatternsFRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
 
Liferay portals in real projects
Liferay portals  in real projectsLiferay portals  in real projects
Liferay portals in real projects
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Angular vs. polymer a face off for the throne of frontend development
Angular vs. polymer  a face off for the throne of frontend developmentAngular vs. polymer  a face off for the throne of frontend development
Angular vs. polymer a face off for the throne of frontend development
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Essential Software Architecture - Chapter 1 Understanding Software Architectu...
Essential Software Architecture - Chapter 1 Understanding Software Architectu...Essential Software Architecture - Chapter 1 Understanding Software Architectu...
Essential Software Architecture - Chapter 1 Understanding Software Architectu...
 
Foster - Getting started with Angular
Foster - Getting started with AngularFoster - Getting started with Angular
Foster - Getting started with Angular
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
 
[Android] DI in multimodule application
[Android] DI in multimodule application[Android] DI in multimodule application
[Android] DI in multimodule application
 
Programming for non tech entrepreneurs
Programming for non tech entrepreneursProgramming for non tech entrepreneurs
Programming for non tech entrepreneurs
 

Libreplan architecture

  • 1. LibrePlan architecture An overview Javier Morán Rúa <jmoran@igalia.com> October 2012
  • 2. Software architecture What is it ? The software architecture of a program or computing system is the structure or structures of the system, which comprise software elements, the externally visible properties of those elements, and the relationships among them. www.libreplan.com
  • 3. Software architecture ● Considerations about architecture: ● Impressive-sounding word. To talk about something is important. ● Many definitions. Not an agreement. ● Three key ideas: – High level design – Difficult to change – Many architectures in one system www.libreplan.com
  • 4. Architectural patterns ● Definition: Description of elements and relation types together with a set of constraints on how they may be used. ● Some traits: ● They guide how to implement new features. ● They exhibit known quality attributes. www.libreplan.com
  • 5. Layering pattern ● Layering: It is a technique to deal with complexity. ● Several layers of software (source code) like in a cake. ● Each layer rests on a lower layer. ● The lower layer is unaware of the upper layer www.libreplan.com
  • 6. Layering pattern ● Benefits: ● You can understand each layer in isolation. ● You can substitute each layer by an alternative implementation. ● They promote reuse. ● They minimize dependencies between structural parts. www.libreplan.com
  • 7. Layering pattern ● Downsides: ● Two much layers can harm performance. ● Desired encapsulation many times is imperfect. Cascade changes. www.libreplan.com
  • 8. Layering pattern ● LibrePlan architecture uses the layering pattern. ● LibrePlan is a three layer (tier) application. ● Layer 0. – Purpose = Persistence – Components = Hibernate framework + Repositories. www.libreplan.com
  • 9. Layering pattern ● Layer 1. – Purpose = Domain logic – Components = Domain Entities, Behavioral classes, Conversational services ● Layer 2. – Purpose = Interfaces (Human + Machine) – Components = ZK web pages, Web services. www.libreplan.com
  • 10. Client - server pattern ● Definition: A program is a client-server application if is a piece of software which runs split it two machines. – Client computer. It makes request to a remote server computer. – Server computer. It does the calculations asked by clients and answers them. www.libreplan.com
  • 11. Client - server pattern ● Some features: ● It implies the existence of a network. ● Client-server applications can be cross-platform. ● Some nodes can be clients and servers at the same time depending on the analyzed role. ● They are related with the layering. Where do you run the layers? www.libreplan.com
  • 12. Client - server pattern ● LibrePlan is a client-server application. ● LibrePlan clients: ● User browser. – Example: Firefox, Google chrome. – Runs part of the interface tier. ● Outer WS client. Example: ERP importing into LibrePlan employees. ● LibrePlan WS client. Example: outsourcing module ● LibrePlan persistence tier. Its server is the RDMS. www.libreplan.com
  • 13. Client - server pattern ● LibrePlan server. ● Runs part of the ZK interface tier, the domain logic and part of the persitence layer. www.libreplan.com
  • 14. Domain model pattern ● What is the domain? Subject area to which the user applies the program. ● LibrePlan domain is project planning, monitoring and control. ● In a few words: Build a model of the domain that both incorporates logic and data. ● What implies? Inserting a whole layer of objects. www.libreplan.com
  • 15. Domain model pattern ● Alternative pattern (more frequently used): Transaction script. ● It what does it consist of? It organizes business logic by procedures where each procedure handles a single request from the presentation. www.libreplan.com
  • 16. Domain model pattern ● Advantages: ● It allows logic reuse on large systems. Typical transaction script architectures promote duplication ● It allows to change easily the behavior of complex domains. It uses the power of the OO model to accomplish it. ● It can be used for knowledge crunching (analysis) with domain experts. Domain driven design. www.libreplan.com
  • 17. Domain model pattern ● Downsides: ● It requires effort. Assimilate the paradigm shift. ● It requires initially more effort to implement. ● LibrePlan uses domain model pattern. ● How is it implemented? ● Hibernate entities are related each other. ● They are POJOs. They can live outside the Hibernate session. www.libreplan.com
  • 18. IoC pattern ● Inversion of Control – Pattern of object-oriented programming where the object coupling is done at run time by an assembler object and is typically not known at compile time by static analysis. ● How is done in traditional programming? ● The flow and the business logic is determined by objects that are statically assigned to one another. www.libreplan.com
  • 19. IoC pattern ● Benefits: ● Decouples the execution of some tasks from specific implementation. It allows to replace components. ● It allows to reuse components more easily (among different programs). ● It allows to focus the components in what they are designed for (cohesion). www.libreplan.com
  • 20. IoC pattern ● Techniques to implement Inversion of Control ● Factory method pattern (GoF). www.libreplan.com
  • 21. IoC pattern ● Using a Service Locator. – An object who knows how to get hold of all the possible services an application can need. – The client component makes explicit calls to the Service Locator ● Using Dependency Injection. www.libreplan.com
  • 22. DI pattern ● Concept: Software design pattern where an element, the injector, places dependent elements to the destination according to the destination requirements. ● Three elements: – A dependent consumer. – A declaration of a component's dependencies. – An injector (aka container or provider) www.libreplan.com
  • 23. DI pattern ● Three types of DI: – Interface injection. The dependent component provides an interface that the consumer must implement in order to get the dependencies at run time. – Setter injection. The dependent consumer exposes a setter method that the injector uses. – Constructor injection. The dependencies are placed in the constructor of the dependent consumer. www.libreplan.com
  • 24. IoC - DI LibrePlan ● LibrePlan uses Inversion of Control. ● LibrePlan implements Inversion of Control with the pattern Dependency Injection. ● LibrePlan uses the Setter Dependency Injection Type. ● LibrePlan uses Spring framework as injector (container) www.libreplan.com
  • 25. IoC – DI LibrePlan ● Spring Framework has about 20 modules. ● Core Container. ● Inside the Core Container the module for IoC and DI is the Core and Beans. ● Where is it used IoC in LibrePlan architecture? ● Getting models from ZK page controllers. ● Getting repositories (DAO) from models. www.libreplan.com
  • 26. MVC pattern ● Model-View-Controller: It is a presentation pattern that consists of splitting the user interface interaction in three roles (Model, View and Controller) ● Model Role. Non-visual object containing all the information and behavior from the application domain. ● View Role. Represents the display of the model in the UI. Example: UI widgets or HTML. It only displays information. www.libreplan.com
  • 27. MVC pattern ● Controller Role. It takes the user input, manipulates the model and causes the view to update accordingly. www.libreplan.com
  • 28. MVC pattern ● Two separations: ● Presentation from the model ● Controller from the view ● Reasons separation presentation from model: ● They are different concerns. ● Depending on context you can use model in different ways. ● Non visual objects are easier to test than visual ones www.libreplan.com
  • 29. MVC pattern ● Separation controller from the view: ● Less important separation. ● This separation is usually not done. ● LibrePlan uses MVC pattern: ● It does not separate controller from view. Many times in the controller is rendered the view (HTML). ● View and the controller split: – Some part runs in the client browser (HTML + JS) – Other part runs in the server (Java objects). www.libreplan.com
  • 30. MVC pattern ● LibrePlan uses the MVC pattern ● The models are injected (DI) with the Spring container into the controllers. ● The models belong to the domain layer and are decoupled by DI from the presentation layer. ● The models are reused sometimes: – HTML view – Web Services www.libreplan.com
  • 31. ZK architecture ● Component based framework. ● It abstracts widgets that are reused in different web pages. Other: Tapestry, Wicket ● Components have two representations: ● DOM in the browser. ● Java objects in the server (POJOs) ● They are synchronized automatically by ZK www.libreplan.com
  • 32. ZK architecture www.libreplan.com
  • 33. ZK architecture ● It is a RIA framework ● Very productive. ● You do not need to program in JS. ● You have not to worry about AJAX for synchronization. ● The best place to manage complex business logic is the server. With ZK you have the domain accessible from the presentation easily. www.libreplan.com
  • 34. LibrePlan and ZK ● LibrePlan uses ZK for the web interface. ● LibrePlan uses the components of ZK CE. ● LibrePlan has developed new ZK components mainly related with the Gantt chart. Examples: ● Task component. ● Dependency component ● Milestone component ● Timetracker component www.libreplan.com
  • 35. Object relational mapping ● Object relational mapping is a technique used for converting the data in a relational database to the object oriented paradigm. ● Hibernate is Java ORM that is the de facto standard in the Java platform for persistence. ● LibrePlan uses Hibernate as ORM in the persistence layer. www.libreplan.com
  • 36. Layers data exchange ● What is an entity? ● An entity is an object defined primarily by its identification. ● It is anything that has continuity through a life-cycle and distinction independent of the attributes that are important for the application's user. Example: Person, city, lottery ticket, etc. www.libreplan.com
  • 37. Repository pattern ● A repository represents all objects of a certain type as a conceptual set. ● Collection with a more elaborate querying capability. ● Clients requests objects from the repository using query methods based on criteria specified by the client. ● Repository retrieves the requested objects, encapsulating the machinery of database queries. www.libreplan.com
  • 38. Repository pattern ● LibrePlan uses the repository pattern. ● They are Java classes called XXXDAO ● They are implemented with Hibernate (HQL, Criteria API). ● They are managed by DI with the Spring container. ● They are injected in the domain Model classes (used in the MVC presentation pattern) ● They are used also in the domain entities but cannot be injected there. They are got from a Registry where they are injected. www.libreplan.com
  • 39. Repository pattern ● In LibrePlan entities are loaded in memory by two ways: ● Using the repositories. ● By traversing the entity relationships. Two conditions: – Hibernate session has to be open. – Objects must be attached. www.libreplan.com
  • 40. Layers data exchange ● Bottom layers offer services to the upper layers by returning data. ● There are two approaches to exchange data between subsystems: Use Data Transfer Objects or return the own data objects of the bottom layer. ● Data Transfer Objects. ● They do not have behavior. ● Only getters and setters. www.libreplan.com
  • 41. Layers data exchange ● Data Transfer Objects: ● They are designed according to client needs. ● Usually aggregate data from several classes of the subsystem that is returning them. ● Analyzing DTOs: ● They are expensive and time-consuming because of the translation code (in - out) www.libreplan.com
  • 42. Layers data exchange ● Analyzing DTOs: ● They are recommendable if the data objects of the service subsystem have inner dependencies. Most of all, for network communications. ● They are comfortable and easy to use by the clients because they are prepared for them. www.libreplan.com
  • 43. Layers data exchange ● LibrePlan use of DTOs in: ● Web services. They are easily converted in XML to be send in the web services body with JAXB (Java Architecture for XML Binding). ● Reports done with JasperReports. The reports require to receive DTOs because of the framework internals. ● LibrePlan uses the domain objects (entities) as layer data exchange. www.libreplan.com
  • 44. Layers data exchange ● Perils of using domain entities (Hibernate mapping objects) as exchange data: Beware of the life cycle. www.libreplan.com
  • 45. Layers data exchange ● Perils of using domain entities (Hibernate mapping objects) as data exchange: Being aware of the graph depth of the objects retrieved. ● You cannot retrieve the full database (performance issues). ● The client has to know the extent of the graph retrieved. If not, LazyInitializationException maybe is thrown. www.libreplan.com
  • 46. Conversations ● LibrePlan is an stateful system. ● Stateless system. At any point the output only depends on the input. ● Stateful system. At a point in time the output depends on the input and internal state. ● You cannot keep the transaction open between user interactions. ● They take a long time and consume resources. ● Maybe they do not finish. www.libreplan.com
  • 47. Conversations ● Conversations are designed in LibrePlan with the pattern session-per-request-with-detached-objects. www.libreplan.com
  • 48. Conversations ● Things to take into account with conversations with detached objects: ● Beware of reattaching objects on asking operations from the controller. ● Avoid having duplicated objects in the session. www.libreplan.com
  • 49. Conversations ● In LibrePlan session-per-request-with-detached objects conversations: ● They happen in the XXXModel objects. ● Model objects are injected by DI in the ZK UI controllers. ● They have prototype scope (not singleton). – The dependent object (XXXModel) is created by Spring before its injection. www.libreplan.com
  • 50. Conversations ● In LibrePlan session-per-request-with-detached objects conversations: ● There is a convention for the conversations: – prepareForOperation() – confirmOperation() www.libreplan.com
  • 51. OCC Pattern ● OCC (Optimistic Concurrency Control) is a pattern that assumes that everything will be OK and that conflicting data modifications are rare. ● OCC raises an error only at the end of a unit of work, when data is written. ● It sets the strategy: First commit wins. www.libreplan.com
  • 52. OCC Pattern www.libreplan.com
  • 53. OCC Pattern ● LibrePlan uses OCC. ● It is got help of Hibernate. ● A version field is used, which is incremented each new update operation. www.libreplan.com
  • 54. Aggregate Pattern ● Problem: In a complex domain it is difficult to guarantee the consistency of changes to objects with complex associations. ● Invariants needs to be maintained in a closed group of objects, not just discrete objects. ● Use the aggregate pattern: An aggregate is a cluster of assocated objects that is treated as a unit for data change operations. www.libreplan.com
  • 55. Aggregate Pattern ● The definition of an aggregate implies: ● To define a boundary. – Defines what is inside the aggregate ● To define the root of the aggregate. – It is a simple specific entity contained in the aggregate www.libreplan.com
  • 56. Aggregate Pattern ● Rules of the pattern: ● The entities outside the aggregate only can hold references to the root aggregate. ● Objects inside the root aggregate can hold references to each other. ● Aggregates root can be got directly with repositories. All other objects must be found by traversal of associations. www.libreplan.com
  • 57. Aggregate Pattern ● Rules of the pattern: ● A delete operation must erase everything inside the aggregate. ● LibrePlan uses Aggregate pattern. ● The XXXModel need to be aware of the aggregates. www.libreplan.com
  • 58. Aggregate Pattern ● Example of aggregate in LibrePlan www.libreplan.com
  • 59. Domain Model Validation ● Problem: Many applications implement validations in many layers. This has two drawbacks: ● Duplication. ● You may not be aware on the validation code you have implement if the application is large. www.libreplan.com
  • 60. Domain Model Validation ● Custom validation scheme: www.libreplan.com
  • 61. Domain Model Validation ● Domain Model Validation in entities: It consists of implementing the validation logic inside domain model entities. www.libreplan.com
  • 62. Domain Model Validation ● LibrePlan uses validation inside domain model entities. ● LibrePlan uses Hibernate Validator to do this process simpler. www.libreplan.com