SlideShare a Scribd company logo
1 of 80
Download to read offline
PADRÕES DE APLICAÇÕES
EMPRESARIAIS
ATRAVÉS DE EXEMPLO


Lição para provas públicas para professor
coordenador na área científica de engenharia
informática


Paulo Gandra Sousa
pag@isep.ipp.pt
Enquadramento da lição
1


     Sessão de “Introdução” de Seminário
       Preparar para o desenvolvimento de aplicações em
       camadas
       Usando as boas práticas da comunidade


     Baseado no livro “Patterns of enterprise application
     architecture” de Martin Fowler

     Através de um exemplo
Inclusão em UC
4




      Passado        Presente        Eventual
                                      futuro
    • EINF         • PARS       •   PARS
    • PARS         • PSIDI      •   PPROG
    • Mobilidade   • EAPLI      •   EAPLI
      Erasmus                   •   ARQSI
                                •   Formação
                                    ao exterior
Língua utilizada
 Inglês

 Partilha dos materiais
   http://www.slideshare.net/pagsousa


 Reutilização de material do Seminário de
 mobilidade Erasmus
PATTERNS OF ENTERPRISE
APPLICATIONS (BY EXAMPLE)
Paulo Sousa
pag@isep.ipp.pt
Goal



 Understand how to develop layered
   enterprise applications by using
      available best practices.
Scope
8




    In scope                  Out of scope
      Layered architectures     ORM
      Business logic            User Interaction
      Data access               SOA
      Distribution              Technology-dependent
                                best practices
                                ...
In every project you have to decide
9

     How to code the Business logic?

     How to represent business entities?

     How to persist its state?

     How to guarantee data coherence?

     How to handle application distribution?

     ...
Driving forces
10


      Ever growing technical complexity
        Networks, internet (www)
        More “potent” OS
        Higher level abstraction libraries/midleware/VM
        Integration with 3rd party applications
      Business
        Higher demand from business
        Higher expectation from business
        Integration with 3rd party businesses
Answers are available. Here.
11


      How to code the Business logic

      How to represent business entities

      How to persist its state

      How to guarantee data coherence

      How to handle application distribution
How will we do it?
12




                      Best practices
                        (patterns)




               Layered             Sample
              Architecture        Application



                  Enterprise Applications
Sessions
13


     1.   Introduction
     2.   Business entities
     3.   Table-oriented Business logic and data access
     4.   Object-oriented Business logic and data access
     5.   Some improvements
     6.   Distributed Applications
     7.   Synopsis
INTRODUCTION
Session 1
Session Goals
15


      Understand the concept of
        Enterprise application
        Software pattern
        Software architecture
        Layered architectures
      Get acquainted with the sample problem
      Get an overview of the rest of the seminar
Session Agenda
16


     1.   Enterprise applications
     2.   Patterns
     3.   Layered architectures
     4.   Sample problem & application
     5.   PoEAA Preview
17




Enterprise Applications
Part 1
18
Enterprise application
19


      Business-critical functionality
      Large quantity of concurrently accessed data
      Large number of screens
      Complex (ilogic) business rules
      Shared resources (sometimes with no ownership)
      Conceptual dissonance
      Integration
Some Enterprise Applications
20
Things that are not EA
21
22




Patterns
Part 2
“Each pattern describes a problem that
   occurs over and over again in our
environment and then describes the core
of the solution to that problem in such a
  way that you can use this solution a
million times over without ever doing it
          the same way twice.”
                   Christopher Alexander (architect)
                                             1979
“A Software Design Pattern names,
abstracts, and identifies the key aspects
of a common design structure that make
 it useful for creating a reusable object-
              oriented design.”
          Design Patterns-Elements of Reusable Object-oriented
                        Software, Gamma et al. (Gang of Four)
                                                         1995
“A particular recurring design problem
 that arises in specific design contexts,
  and presents a well-proven generic
   scheme for its solution. The solution
  scheme is specified by describing its
     constituent components, their
responsibilities and relationships, and
  the ways in which they collaborate”
            Pattern Oriented Software Architecture, volume 1
                                       Bushman et al. 1996
To sum up:
27




     General      Recuring   Context   Pattern
     solution     problem
A pattern is
28


      a set of (field-tested) best practices

      found not invented

      a way to facilitate communication

      Most of the time used in combination with other
      patterns
“Patterns are half-baked”

                       Martin Fowler
not
Challenges
31


      No direct code reuse

      Pattern overload

      Experience-based validation

      Hard work integrating patterns in the development
      process
Key Principles
 Program to an interface not an implementation
   Decreases coupling/dependencies among classes

 Favour composition instead of inheritance
   Don’t inherit behaviour you don’t need. Allow for
   implementation changes

 Consider what should be variable in your design
   Encapsulate what varies and allow for substitution via
   common interface
Pattern description
33


     name             Contributes to the pattern
                      vocabulary
     synopsis         Short description of the problem the
                      pattern will solve.
     forces           Requirements, considerations, or
                      necessary conditions
     solution         The essence of the solution
     counter forces   Reasons for not using the pattern.
     related patterns Possible alternatives in the design.
At this final stage [...] the patterns
 aren’t important. The forces in the
problem domain and how to resolve
               them are.
                    Christopher Alexander (1979)
35




Layered Architecture
Part 3
“Software Architecture is the
fundamental organization of a system,
   embodied in its components, their
  relationships to each other and the
    environment, and the principles
 governing its design and evolution.“
        ANSI/IEEE Std 1471-2000, Recommended Practice for
        Architectural Description of Software-Intensive Systems
“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.
"Externally visible” properties refers to those
assumptions other elements can make of an
   element, such as its provided services,
 performance characteristics, fault handling,
     shared resource usage, and so on. “
                        Software Architecture in Practice (2003)
A reference model: 3-Layers
38




                               Application


                                              Data
                Presentation   Business
                                             Access
                   Logic        Logic
                                              Logic
PGS14



        3 layers
 39

                                                      PessoaForm
        Presentation                             + ButtonOK_Click ( )
        Layer                                    + Close ( )                                         Business rules
                                                                                                           +
                                                                                                      Persistence
                                                         Pessoa                                       commands
                         - Nome : string
                         - dtNascimento : DateTime
        Business Logic   + SetDataNascimento ( [in] dt : DateTime )
                         + SetDataNascimento ( [in] ano : int , [in] mes : int , [in] dia : int )
        Layer            + GetIdade ( ) : int
                         + LoadById ( [in] ID : int ) : Pessoa
                         + Save ( )
                                                                                                    A generic
                                                                                                    component forces
                                                                                                    the business
                                                     AcessoDados
                                                                                                    Layer to know
        Data Access                  + AbreConexao ( ) : IConnection                                SQL
                                     + ExecutaSelect ( [in] sql : string ) : DataSet
        Layer                        + ExecutaUpdate ( [in] sql : string ) : int                    Thus it is not a
                                     + FechaConexao ( [in] cnx : IConnection )
                                                                                                    data layer
Slide 40

PGS14      incluir estes 3 slides?
           Paulo G Sousa; 26-02-2010
3 layers
40


                                                   PessoaForm

                                              + ButtonOK_Click ( )
                                              + Close ( )




                                                      Pessoa

     Business rules   - Nome : string
                      - dtNascimento : DateTime
           +
                      + SetDataNascimento ( [in] dt : DateTime )
      Persistence     + SetDataNascimento ( [in] ano : int , [in] mes : int , [in] dia : int )
      commands        + GetIdade ( ) : int
                      + LoadById ( [in] ID : int ) : Pessoa
                      + Save ( )



                                                                                                   Methods for
                                                   PessoaDAL
                                                                                                   data access
                      + Insert ( [in] nome : string , [in] dtNasc : DateTime ) : int               hidding the
                      + Update ( [in] int ID , [in] nome : string , [in] dtNasc : DateTime )
                      + Delete ( [in] ID : int )                                                 implementation
                      + FindByID ( [in] ID : in ) : DataRow
                                                                                                    aspects of
                                                                                                   persistence
3 layers
41


                                PessoaForm


                                                                                                                Data access
                                 Pessoa                                                            Morada
                                                                                                                component
         DAL

                                     PessoaDAL                                                  MoradaDAL

         + Insert ( [in] nome : string , [in] dtNasc : DateTime ) : int                        + FindByID ( )
         + Update ( [in] int ID , [in] nome : string , [in] dtNasc : DateTime )                + Update ( )
         + Delete ( [in] ID : int )                                                            + Delete ( )
         + FindByID ( [in] ID : in ) : DataRow                                                 + Insert ( )




                                                       BaseDAL
                 + CONNECTION : string

                 + AbrirConexao ( ) : IConnection
                                                                                                                 Internal
                 + ExecutarQuery ( [in] sql : string ) : DataSet                                                (package)
                 + ExecutarUpdate ( [in] sql : string ) : int
                 + FindByID ( [in] tabela : string , [in] campo : string , [in] chave : int ) : DataRow         base class
source: Microsoft Application Architecture Guide 2.0
Layers vs. Tiers
43




                        fonte: Application Architecture for .NET:
                           designing applications and Services
Sample problem & Application
Part 4
The problem: Revenue Recognition
45


     Customer                   Contract                         Product
                 1                          *
     + name                 + revenue                          + name
                          * + dateSigned                   1

                                    1

                                                 WordProcessor              SpreadSheet
                                *

                         RevenueRecognition

                        + dateRecognition                        DataBase
                        + amount



        Different payment rules
                WP – all at once (t)
                DB – 3 payments: t, t+30, t+60
                SS – 3 payments: t, t+60, t+90
                                                (From Martin Fowler’s PoEAA book)
Requirements
46


      For a given contract, calculate when each revenue
      will happen and the amount due

      For a given contract, calculate how much revenue it
      has generated as of a certain date
Business interface
47



     public interface IRevenueRecognition
     {
       void CalculateRevenueRecognitions(int contractID);

         Money RecognizedRevenue(int contractID, DateTime asOf);

         object GetContracts();

         object GetCustomers();

         object GetProducts();
     }
Relational model
48




                                           «table»
                                     TRevenueRecognitions

                                 + «Column» ID : int
                                 + «Column» contractID : int
                                 + «Column» dateRecognition : date
                                 + «Column» amount : currency




                                            «table»
                                                                             «table»
                                          TContracts
             «table»                                                        TProducts
           TCustomers            + «Column» ID : int
                                                                     + «Column» ID : int
                                 + «Column» productID : int
     + «Column» ID : int                                             + «Column» type : varchar
                                 + «Column» customerID : int
     + «Column» name : varchar                                       + «Column» name : varchar
                                 + «Column» revenue : currency
                                 + «Column» dateSigned : date
The workbench application
49


                                                                     Architectural
                                                                         style



     output

                                                                      Business
                                                                     operations




       http://w2ks.dei.isep.ipp.pt/psousa/GetFile.aspx?file=PoEAAWorkbench.zip
Remember the questions?
50


      The workbench will show
        How to represent the business entities
        How to persist its state
        How to code the Business logic
        How to guarantee data coherence


      The workbench will not show
        How to handle application distribution
The first big question
51




                  Table-oriented

                      Versus

                  Object-oriented
Architectural examples
52


      Table oriented
        Table Module + Table Data Gateway (DataSet)
        Table Module + Table Data Gateway (Custom Classes)


      Object-oriented
        Domain Model + Active Record
        Domain Model + Data Mapper
Architectural examples
53

      Transaction Script using DataSet
        Transaction Script
        Transaction Script + Data Gateway
      Transaction Script using Custom Classes
        Transaction Script
        Transaction Script + Row Data Gateway
      Table Module
        Table Module + Table Data Gateway (DataSet)
        Table Module + Table Data Gateway (Custom Classes)
                                                             focus
      Domain Model
        Domain Model + Active Record
        Domain Model + Data Mapper
Workbench’s architecture
54


                                                    Different arch.
                                                Styles. These are the
                                                 classes to “look” at




                   RevenueGUI   RevenueFacade            implementation




                                  Common
The RevenueFacade layer
55

      A combination of a Factory, a
      Singleton and a Façade

      The desired implementation is
      loaded into memory and an
      instance of the specific
      façade is created (reflection)
      and returned to the GUI

      The UI layer will then interact
      with the business layer via the
      IRevenueRecognition business
      interface ignoring the actual
      implementation
Pattern
     Factory
56


      Problem:
        How to hide the details of object creation specially
        when there are special conditions on how and which
        object (interface implementation) to create?


      Solution:
        Create an object whose sole responsibility is to create
        other objects based on context information and hiding
        de details of that potentially complex creation
Pattern
     Factory
57


      Provides a way to hide complexity of object
      creation
Pattern GoF
Façade
 Problem:
   Actual work is performed by two or more objects, but
   you want to hide this level of complexity from the client.


 Solution:
   Create a facade object that receives the messages, but
   passes commands on to the workers for completion.
Pattern GoF
     Façade
59


      Provide a unified interface to a set of interfaces in a subsystem.
      Façade defines a higher-level interface that makes the subsystem
      easier to use.




                source: Design Patterns: Elements of Reusable Object-Oriented Software
Pattern GoF
Singleton
 Problem:
   You want to ensure that there is never more than one
   instance of a given class.


 Solution:
   Make the constructor private, have a method that
   returns just one instance, which is held inside the class
   itself.
Pattern GoF
     Singleton
61


      Ensure a class has only one instance and provide a
      global point of access to it.




             soure: Design Patterns: Elements of Reusable Object-Oriented Software
DEMO
62
PoEAA Preview
Part 5
Business entities
 Record Set versus Custom class

 One versus many

 Relationships (networks, hierarchies, etc.)

 XML
Table-oriented: Packages

  TM+TDG                               TM+TDG+CC
            UI                                 UI




      «table module»                    «table module»               Entities
            BLL                               BLL




                                                              These classes
   «table data gateway»
            DAL
                                       «table data gateway»     have only
                                                DAL
                                                                attributes

                    Uses the plaform
                      Record Set
Table oriented: Table Module

                                                 Contract

                + Contract ( )
                + RecognizedRevenue ( [in] contractID : int , [in] asOf : DateTime ) : Money
                + CalculateRevenueRecognitions ( [in] contractID : int )
                + GetContracts ( ) : DataSet
                + GetContractsByProduct ( [in] productID : int ) : DataSet
                + GetContractsByCustomer ( [in] customerID : int ) : DataSet



                                             Customer
  One class per
      table                       + Customer ( )
                                  + GetCustomers ( ) : DataTable
  handles all the
  records in the
      table                                   Product

                                   + Product ( )
                                   + GetProducts ( ) : DataTable
Table oriented: CalculateRevenues
/ User : Actor1            / GUI                   / ClassifierRole1 : Contract


      1 : btnCalcRevenues_Click
                             2 : CalculateRevenueRecognitions (
                                         contractID )
                                                                    3 : new                  / ClassifierRole2 : Contract
                                                                                                         Gateway

                                                                  4 : GetContractByID ( contractID )



                                                                    5 : BeginTransaction ( )



                                                                  6 : InsertRecognition ( contractID ,                        foreach calculated
                                                                       recognitionDate , amount )                             recognition



                                                                    7 : CommitTransaction ( )
Object-oriented: Packages

   DM+AR                                       DM+DM
       GUI                                           UI




                                    «domain model»
   «domain model + active record»                         «data mapper»
                                         BLL
            BLL + DAL                                          DAL




                                                              Database
Object-oriented: Domain Model
                                                       Customer                                                          Contract
                                                 - _ID : int                            + «property» Product : Product
                                                 - _name : string                       - _ID : int
    True OO model;                               + «property» ID : int - _Customer      - _CustomerID : int
                                                                                        - _DateSigned : DateTime
      each object                                + Customer ( )                         - _ProductID : int
                                                 + «get» ID ( ) : int
    handle one entity                                                                   - _Revenue : decimal
                                                                                        + «property» Customer : Customer
       (“record”)                                     Product                           + «property» RevenueRecognitions : IList
                                                                                        + «property» DateSigned : DateTime
                                            + «property» Type : string                  + «property» Revenue : decimal
                                            - _ID : int                                 + «property» ID : int
                                            - _name : string
                                            - _type : string                            ~ AddRecognition ( [in] recognitionDate : DateTime , [in] amount : decimal )
                                            + «property» ID : int                       + Contract ( )
                                                                                        + RecognizedRevenue ( [in] asOf : DateTime ) : Money
                                            + Product ( )                 - _Product    + CalculateRevenueRecognitions ( )
                                            + «get» Type ( ) : string                   + «get» Product ( ) : Product
                                            + «get» ID ( ) : int                        ~ SetID ( [in] id : int )
                                                                                        ~ SetProduct ( [in] prodID : int , [in] prodType : string )
                                   IRevenueRecognitionStrategy                          - SetStrategy ( [in] prodType : string )
                                                                        - theStrategy   ~ SetProduct ( [in] prodID : int )
                                                                                        + «get» Customer ( ) : Customer
                                                                                        + «get» RevenueRecognitions ( ) : IList
                            RevenueRecognition                                          + «get» DateSigned ( ) : DateTime
                                                                                        + «get» Revenue ( ) : decimal
+ Amount : decimal
                                                                                        + «get» ID ( ) : int
+ DateRecognition : DateTime
                                                                                        ~ SetCustomer ( [in] custID : int )
+ ID : int
                                                                                        + «set» Product ( [in] value : Product )
+ RevenueRecognition ( [in] id : int , [in] dt : DateTime , [in] amt : decimal )        + «set» DateSigned ( [in] value : DateTime )
+ RevenueRecognition ( [in] dt : DateTime , [in] amt : decimal )                        + «set» Revenue ( [in] value : decimal )
                                                                *                                                A Workbench for Learning
                                     - _RevenueRecognitions
                                                                                                                 Enterprise Patterns
Object-oriented: CalculateRevenues
: Actor1              / UI         / c : Contract                            : IRevenueRecognitionStrategy       : ContractMapper             : DBFactory

    1 : btnCalc_Click
                      2 : CalculateRevenueRecognitions ( )
                                             3 : CalculateRevenueRecognitions ( )



                                                    4 : AddRecognition ( recognitionDate ,
                                                                 amount )

                                                                                foreach recognized
                                                                                revenue
                                         5 : Save ( c )
                                                                                                                         6 : CreateDBHelper ( )
                                                                                                                                                    7 : new
                                                                                                                                                                : IDBHelper

                                                                                                                             8 : BeginTransaction ( )

                                                                                                                          9 : ExecuteTransactedNonQuery ( cmd
                                                                                                                                            )

                                                                                                                           10 : ExecuteTransactedNonQuery (
                                                                                   foreach recognized revenue                            cmd )


                                                                                                                             11 : CommitTransaction ( )




                                                                                                                       A Workbench for Learning
                                                                                                                70
                                                                                                                       Enterprise Patterns
Problems with domain model
 How to avoid networks of objects to be fully loaded into
 memory when only a few “fields” are necessary
   Lazy Load

 How to guarantee that there are no multiple in memory
 representations of the same “db entity”
   Identity Field
   Identity Map

 How to allow for variations of the same algorithm?
   Strategy
   To embed each recognition rule in the Domain model
Distributed applications
72




               contract
To conclude
Session synopsis
74


      Introduced the concept of
        Enterprise application
        Software pattern
        Software architecture
        Layered architectures
      Presented the sample problem
      Presented an overview of the rest of the seminar
At this final stage [...] The patterns
 aren’t important. The forces in the
problem domain and how to resolve
               them are.
                    Christopher Alexander (1979)
Patterns of Enterprise
                   Applications (by Example)




          Paulo Sousa
  76
ISEP/IP
          pag@isep.ipp.pt      http://linkedin.com/in/pagsousa
   P
REFERENCES
Bibliography
78

      Fowler, Martin. Patterns of Enterprise Application Architecture. Adisson-
      Wesley.
      Erich Gamma, Richard Helm, Ralph Johnson, John Vissides. Design patterns :
      elements of reusable object-oriented software. Adisson-Wesley.
      Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael
      Stal. Pattern-oriented Software Architecture: System of Patterns.
      Buschmann, F.; Henney, K. And Schmidt, D. (2007) Pattern-Oriented
      Software Architecture: A Pattern Language for Distributed Computing,
      Volume 4. Willey.
      Deepak Alur, John Crupi and Dan Malks. Core J2EE Patterns: Best Practices
      and Design Strategies. Prentice Hall / Sun Microsystems Press.
      http://java.sun.com/blueprints/corej2eepatterns/index.html
      Enterprise Solution Patterns Using Microsoft .NET. Microsoft Press.
      http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar
      y/en-us/dnpatterns/html/Esp.asp
      Designing Data Tier Components and Passing Data Through Tiers. Microsoft
      Patterns & Practices. http://msdn.microsoft.com/library/?url=/library/en-
      us/dnbda/html/BOAGag.asp?frame=true
Bibliography
79


      Domain logic and SQL. Martin Fowler.
      http://www.martinfowler.com/articles/dblogic.htm
      l
      Why extends is evil. Allen Holub
      http://www.javaworld.com/javaworld/jw-08-
      2003/jw-0801-toolbox.html
      Why getter and setter methods are evil . Allen Holub
      http://www.javaworld.com/javaworld/jw-09-
      2003/jw-0905-toolbox.html
      Domain logic and SQL. Martin Fowler.
      http://www.martinfowler.com/articles/dblogic.html
      Public vs. Published interfaces. Martin Fowler.
      http://www.martinfowler.com/ieeeSoftware/publi
      shed.pdf
      Don’t live with Broken windows
      http://www.artima.com/intv/fixit.html
Pattern catalogs
80

      GoF Design patterns (em C#)
      http://www.dofactory.com/Patterns/Patterns.aspx
      GoF & POSA Design patterns (em Java)
      http://www.vico.org/pages/PatronsDisseny.html
      Patterns of Enterprise Application architecture
      http://martinfowler.com/eaaCatalog/
      Core J2EE Patterns
      http://www.corej2eepatterns.com
      Enterprise Solution Patterns Using Microsoft .NET.
      http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar
      y/en-us/dnpatterns/html/Esp.asp
      Patterns of Enterprise Application Integration
      http://www.enterpriseintegrationpatterns.com/
      Enterprise Java Patterns @ The Server Side
      http://www.theserverside.com/patterns/index.tss
      Microsoft Data Patterns
      http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar
      y/en-us/dnpatterns/html/Dp.asp

More Related Content

Viewers also liked (12)

Communication
CommunicationCommunication
Communication
 
OO design principles and patterns
OO design principles and patternsOO design principles and patterns
OO design principles and patterns
 
Benefits of Hypermedia API
Benefits of Hypermedia APIBenefits of Hypermedia API
Benefits of Hypermedia API
 
Design Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID codeDesign Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID code
 
Modern web architectural patterns
Modern web architectural patternsModern web architectural patterns
Modern web architectural patterns
 
Principles of Service Orientation
Principles of Service OrientationPrinciples of Service Orientation
Principles of Service Orientation
 
REST beyond CRUD
REST beyond CRUDREST beyond CRUD
REST beyond CRUD
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
 
Patterns for distributed systems
Patterns for distributed systemsPatterns for distributed systems
Patterns for distributed systems
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
 

Similar to Lição prova professor coordenador

Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
Kahn.theodore
Kahn.theodoreKahn.theodore
Kahn.theodoreNASAPMC
 
Management of Complexity in System Design of Large IT Solutions
Management of Complexity in System Design of Large IT SolutionsManagement of Complexity in System Design of Large IT Solutions
Management of Complexity in System Design of Large IT SolutionsMichael Heiss
 
Domain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureDomain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureCan Pekdemir
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architectureTot Bob
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven designTim Mahy
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxArifaMehreen1
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software DevelopmentJignesh Patel
 
Basics of Software Architecture for .NET Developers
Basics of Software Architecture for .NET DevelopersBasics of Software Architecture for .NET Developers
Basics of Software Architecture for .NET DevelopersDan Douglas
 
SAF 2008 - Analysis and Architecture
SAF 2008 - Analysis  and ArchitectureSAF 2008 - Analysis  and Architecture
SAF 2008 - Analysis and Architecturemhessinger
 
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015Mozaic Works
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIRobert Lemke
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architecturesMajong DevJfu
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-oplbergmans
 
Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patternspedro
 
Software arquitectura patron diseño
Software arquitectura patron diseñoSoftware arquitectura patron diseño
Software arquitectura patron diseñopedro
 

Similar to Lição prova professor coordenador (20)

Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Kahn.theodore
Kahn.theodoreKahn.theodore
Kahn.theodore
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Management of Complexity in System Design of Large IT Solutions
Management of Complexity in System Design of Large IT SolutionsManagement of Complexity in System Design of Large IT Solutions
Management of Complexity in System Design of Large IT Solutions
 
Domain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureDomain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal Architecture
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architecture
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven design
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptx
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Basics of Software Architecture for .NET Developers
Basics of Software Architecture for .NET DevelopersBasics of Software Architecture for .NET Developers
Basics of Software Architecture for .NET Developers
 
SAF 2008 - Analysis and Architecture
SAF 2008 - Analysis  and ArchitectureSAF 2008 - Analysis  and Architecture
SAF 2008 - Analysis and Architecture
 
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
 
Resume
ResumeResume
Resume
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DI
 
2009-dec-10 Architectuur en HL7
2009-dec-10 Architectuur en HL72009-dec-10 Architectuur en HL7
2009-dec-10 Architectuur en HL7
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architectures
 
Slides chapter 9
Slides chapter 9Slides chapter 9
Slides chapter 9
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-op
 
Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patterns
 
Software arquitectura patron diseño
Software arquitectura patron diseñoSoftware arquitectura patron diseño
Software arquitectura patron diseño
 

More from Paulo Gandra de Sousa

More from Paulo Gandra de Sousa (9)

Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Minds-on DDD
Minds-on DDDMinds-on DDD
Minds-on DDD
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
Hypermedia APIs
Hypermedia APIsHypermedia APIs
Hypermedia APIs
 
Revision control with Mercurial
Revision control with MercurialRevision control with Mercurial
Revision control with Mercurial
 
Documenting Software Architectures
Documenting Software ArchitecturesDocumenting Software Architectures
Documenting Software Architectures
 
models of distributed computing
models of distributed computingmodels of distributed computing
models of distributed computing
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 

Recently uploaded

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 

Lição prova professor coordenador

  • 1. PADRÕES DE APLICAÇÕES EMPRESARIAIS ATRAVÉS DE EXEMPLO Lição para provas públicas para professor coordenador na área científica de engenharia informática Paulo Gandra Sousa pag@isep.ipp.pt
  • 2. Enquadramento da lição 1 Sessão de “Introdução” de Seminário Preparar para o desenvolvimento de aplicações em camadas Usando as boas práticas da comunidade Baseado no livro “Patterns of enterprise application architecture” de Martin Fowler Através de um exemplo
  • 3. Inclusão em UC 4 Passado Presente Eventual futuro • EINF • PARS • PARS • PARS • PSIDI • PPROG • Mobilidade • EAPLI • EAPLI Erasmus • ARQSI • Formação ao exterior
  • 4. Língua utilizada Inglês Partilha dos materiais http://www.slideshare.net/pagsousa Reutilização de material do Seminário de mobilidade Erasmus
  • 5. PATTERNS OF ENTERPRISE APPLICATIONS (BY EXAMPLE) Paulo Sousa pag@isep.ipp.pt
  • 6. Goal Understand how to develop layered enterprise applications by using available best practices.
  • 7. Scope 8 In scope Out of scope Layered architectures ORM Business logic User Interaction Data access SOA Distribution Technology-dependent best practices ...
  • 8. In every project you have to decide 9 How to code the Business logic? How to represent business entities? How to persist its state? How to guarantee data coherence? How to handle application distribution? ...
  • 9. Driving forces 10 Ever growing technical complexity Networks, internet (www) More “potent” OS Higher level abstraction libraries/midleware/VM Integration with 3rd party applications Business Higher demand from business Higher expectation from business Integration with 3rd party businesses
  • 10. Answers are available. Here. 11 How to code the Business logic How to represent business entities How to persist its state How to guarantee data coherence How to handle application distribution
  • 11. How will we do it? 12 Best practices (patterns) Layered Sample Architecture Application Enterprise Applications
  • 12. Sessions 13 1. Introduction 2. Business entities 3. Table-oriented Business logic and data access 4. Object-oriented Business logic and data access 5. Some improvements 6. Distributed Applications 7. Synopsis
  • 14. Session Goals 15 Understand the concept of Enterprise application Software pattern Software architecture Layered architectures Get acquainted with the sample problem Get an overview of the rest of the seminar
  • 15. Session Agenda 16 1. Enterprise applications 2. Patterns 3. Layered architectures 4. Sample problem & application 5. PoEAA Preview
  • 17. 18
  • 18. Enterprise application 19 Business-critical functionality Large quantity of concurrently accessed data Large number of screens Complex (ilogic) business rules Shared resources (sometimes with no ownership) Conceptual dissonance Integration
  • 20. Things that are not EA 21
  • 22.
  • 23. “Each pattern describes a problem that occurs over and over again in our environment and then describes the core of the solution to that problem in such a way that you can use this solution a million times over without ever doing it the same way twice.” Christopher Alexander (architect) 1979
  • 24. “A Software Design Pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object- oriented design.” Design Patterns-Elements of Reusable Object-oriented Software, Gamma et al. (Gang of Four) 1995
  • 25. “A particular recurring design problem that arises in specific design contexts, and presents a well-proven generic scheme for its solution. The solution scheme is specified by describing its constituent components, their responsibilities and relationships, and the ways in which they collaborate” Pattern Oriented Software Architecture, volume 1 Bushman et al. 1996
  • 26. To sum up: 27 General Recuring Context Pattern solution problem
  • 27. A pattern is 28 a set of (field-tested) best practices found not invented a way to facilitate communication Most of the time used in combination with other patterns
  • 29. not
  • 30. Challenges 31 No direct code reuse Pattern overload Experience-based validation Hard work integrating patterns in the development process
  • 31. Key Principles Program to an interface not an implementation Decreases coupling/dependencies among classes Favour composition instead of inheritance Don’t inherit behaviour you don’t need. Allow for implementation changes Consider what should be variable in your design Encapsulate what varies and allow for substitution via common interface
  • 32. Pattern description 33 name Contributes to the pattern vocabulary synopsis Short description of the problem the pattern will solve. forces Requirements, considerations, or necessary conditions solution The essence of the solution counter forces Reasons for not using the pattern. related patterns Possible alternatives in the design.
  • 33. At this final stage [...] the patterns aren’t important. The forces in the problem domain and how to resolve them are. Christopher Alexander (1979)
  • 35. “Software Architecture is the fundamental organization of a system, embodied in its components, their relationships to each other and the environment, and the principles governing its design and evolution.“ ANSI/IEEE Std 1471-2000, Recommended Practice for Architectural Description of Software-Intensive Systems
  • 36. “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. "Externally visible” properties refers to those assumptions other elements can make of an element, such as its provided services, performance characteristics, fault handling, shared resource usage, and so on. “ Software Architecture in Practice (2003)
  • 37. A reference model: 3-Layers 38 Application Data Presentation Business Access Logic Logic Logic
  • 38. PGS14 3 layers 39 PessoaForm Presentation + ButtonOK_Click ( ) Layer + Close ( ) Business rules + Persistence Pessoa commands - Nome : string - dtNascimento : DateTime Business Logic + SetDataNascimento ( [in] dt : DateTime ) + SetDataNascimento ( [in] ano : int , [in] mes : int , [in] dia : int ) Layer + GetIdade ( ) : int + LoadById ( [in] ID : int ) : Pessoa + Save ( ) A generic component forces the business AcessoDados Layer to know Data Access + AbreConexao ( ) : IConnection SQL + ExecutaSelect ( [in] sql : string ) : DataSet Layer + ExecutaUpdate ( [in] sql : string ) : int Thus it is not a + FechaConexao ( [in] cnx : IConnection ) data layer
  • 39. Slide 40 PGS14 incluir estes 3 slides? Paulo G Sousa; 26-02-2010
  • 40. 3 layers 40 PessoaForm + ButtonOK_Click ( ) + Close ( ) Pessoa Business rules - Nome : string - dtNascimento : DateTime + + SetDataNascimento ( [in] dt : DateTime ) Persistence + SetDataNascimento ( [in] ano : int , [in] mes : int , [in] dia : int ) commands + GetIdade ( ) : int + LoadById ( [in] ID : int ) : Pessoa + Save ( ) Methods for PessoaDAL data access + Insert ( [in] nome : string , [in] dtNasc : DateTime ) : int hidding the + Update ( [in] int ID , [in] nome : string , [in] dtNasc : DateTime ) + Delete ( [in] ID : int ) implementation + FindByID ( [in] ID : in ) : DataRow aspects of persistence
  • 41. 3 layers 41 PessoaForm Data access Pessoa Morada component DAL PessoaDAL MoradaDAL + Insert ( [in] nome : string , [in] dtNasc : DateTime ) : int + FindByID ( ) + Update ( [in] int ID , [in] nome : string , [in] dtNasc : DateTime ) + Update ( ) + Delete ( [in] ID : int ) + Delete ( ) + FindByID ( [in] ID : in ) : DataRow + Insert ( ) BaseDAL + CONNECTION : string + AbrirConexao ( ) : IConnection Internal + ExecutarQuery ( [in] sql : string ) : DataSet (package) + ExecutarUpdate ( [in] sql : string ) : int + FindByID ( [in] tabela : string , [in] campo : string , [in] chave : int ) : DataRow base class
  • 42. source: Microsoft Application Architecture Guide 2.0
  • 43. Layers vs. Tiers 43 fonte: Application Architecture for .NET: designing applications and Services
  • 44. Sample problem & Application Part 4
  • 45. The problem: Revenue Recognition 45 Customer Contract Product 1 * + name + revenue + name * + dateSigned 1 1 WordProcessor SpreadSheet * RevenueRecognition + dateRecognition DataBase + amount Different payment rules WP – all at once (t) DB – 3 payments: t, t+30, t+60 SS – 3 payments: t, t+60, t+90 (From Martin Fowler’s PoEAA book)
  • 46. Requirements 46 For a given contract, calculate when each revenue will happen and the amount due For a given contract, calculate how much revenue it has generated as of a certain date
  • 47. Business interface 47 public interface IRevenueRecognition { void CalculateRevenueRecognitions(int contractID); Money RecognizedRevenue(int contractID, DateTime asOf); object GetContracts(); object GetCustomers(); object GetProducts(); }
  • 48. Relational model 48 «table» TRevenueRecognitions + «Column» ID : int + «Column» contractID : int + «Column» dateRecognition : date + «Column» amount : currency «table» «table» TContracts «table» TProducts TCustomers + «Column» ID : int + «Column» ID : int + «Column» productID : int + «Column» ID : int + «Column» type : varchar + «Column» customerID : int + «Column» name : varchar + «Column» name : varchar + «Column» revenue : currency + «Column» dateSigned : date
  • 49. The workbench application 49 Architectural style output Business operations http://w2ks.dei.isep.ipp.pt/psousa/GetFile.aspx?file=PoEAAWorkbench.zip
  • 50. Remember the questions? 50 The workbench will show How to represent the business entities How to persist its state How to code the Business logic How to guarantee data coherence The workbench will not show How to handle application distribution
  • 51. The first big question 51 Table-oriented Versus Object-oriented
  • 52. Architectural examples 52 Table oriented Table Module + Table Data Gateway (DataSet) Table Module + Table Data Gateway (Custom Classes) Object-oriented Domain Model + Active Record Domain Model + Data Mapper
  • 53. Architectural examples 53 Transaction Script using DataSet Transaction Script Transaction Script + Data Gateway Transaction Script using Custom Classes Transaction Script Transaction Script + Row Data Gateway Table Module Table Module + Table Data Gateway (DataSet) Table Module + Table Data Gateway (Custom Classes) focus Domain Model Domain Model + Active Record Domain Model + Data Mapper
  • 54. Workbench’s architecture 54 Different arch. Styles. These are the classes to “look” at RevenueGUI RevenueFacade implementation Common
  • 55. The RevenueFacade layer 55 A combination of a Factory, a Singleton and a Façade The desired implementation is loaded into memory and an instance of the specific façade is created (reflection) and returned to the GUI The UI layer will then interact with the business layer via the IRevenueRecognition business interface ignoring the actual implementation
  • 56. Pattern Factory 56 Problem: How to hide the details of object creation specially when there are special conditions on how and which object (interface implementation) to create? Solution: Create an object whose sole responsibility is to create other objects based on context information and hiding de details of that potentially complex creation
  • 57. Pattern Factory 57 Provides a way to hide complexity of object creation
  • 58. Pattern GoF Façade Problem: Actual work is performed by two or more objects, but you want to hide this level of complexity from the client. Solution: Create a facade object that receives the messages, but passes commands on to the workers for completion.
  • 59. Pattern GoF Façade 59 Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use. source: Design Patterns: Elements of Reusable Object-Oriented Software
  • 60. Pattern GoF Singleton Problem: You want to ensure that there is never more than one instance of a given class. Solution: Make the constructor private, have a method that returns just one instance, which is held inside the class itself.
  • 61. Pattern GoF Singleton 61 Ensure a class has only one instance and provide a global point of access to it. soure: Design Patterns: Elements of Reusable Object-Oriented Software
  • 64. Business entities Record Set versus Custom class One versus many Relationships (networks, hierarchies, etc.) XML
  • 65. Table-oriented: Packages TM+TDG TM+TDG+CC UI UI «table module» «table module» Entities BLL BLL These classes «table data gateway» DAL «table data gateway» have only DAL attributes Uses the plaform Record Set
  • 66. Table oriented: Table Module Contract + Contract ( ) + RecognizedRevenue ( [in] contractID : int , [in] asOf : DateTime ) : Money + CalculateRevenueRecognitions ( [in] contractID : int ) + GetContracts ( ) : DataSet + GetContractsByProduct ( [in] productID : int ) : DataSet + GetContractsByCustomer ( [in] customerID : int ) : DataSet Customer One class per table + Customer ( ) + GetCustomers ( ) : DataTable handles all the records in the table Product + Product ( ) + GetProducts ( ) : DataTable
  • 67. Table oriented: CalculateRevenues / User : Actor1 / GUI / ClassifierRole1 : Contract 1 : btnCalcRevenues_Click 2 : CalculateRevenueRecognitions ( contractID ) 3 : new / ClassifierRole2 : Contract Gateway 4 : GetContractByID ( contractID ) 5 : BeginTransaction ( ) 6 : InsertRecognition ( contractID , foreach calculated recognitionDate , amount ) recognition 7 : CommitTransaction ( )
  • 68. Object-oriented: Packages DM+AR DM+DM GUI UI «domain model» «domain model + active record» «data mapper» BLL BLL + DAL DAL Database
  • 69. Object-oriented: Domain Model Customer Contract - _ID : int + «property» Product : Product - _name : string - _ID : int True OO model; + «property» ID : int - _Customer - _CustomerID : int - _DateSigned : DateTime each object + Customer ( ) - _ProductID : int + «get» ID ( ) : int handle one entity - _Revenue : decimal + «property» Customer : Customer (“record”) Product + «property» RevenueRecognitions : IList + «property» DateSigned : DateTime + «property» Type : string + «property» Revenue : decimal - _ID : int + «property» ID : int - _name : string - _type : string ~ AddRecognition ( [in] recognitionDate : DateTime , [in] amount : decimal ) + «property» ID : int + Contract ( ) + RecognizedRevenue ( [in] asOf : DateTime ) : Money + Product ( ) - _Product + CalculateRevenueRecognitions ( ) + «get» Type ( ) : string + «get» Product ( ) : Product + «get» ID ( ) : int ~ SetID ( [in] id : int ) ~ SetProduct ( [in] prodID : int , [in] prodType : string ) IRevenueRecognitionStrategy - SetStrategy ( [in] prodType : string ) - theStrategy ~ SetProduct ( [in] prodID : int ) + «get» Customer ( ) : Customer + «get» RevenueRecognitions ( ) : IList RevenueRecognition + «get» DateSigned ( ) : DateTime + «get» Revenue ( ) : decimal + Amount : decimal + «get» ID ( ) : int + DateRecognition : DateTime ~ SetCustomer ( [in] custID : int ) + ID : int + «set» Product ( [in] value : Product ) + RevenueRecognition ( [in] id : int , [in] dt : DateTime , [in] amt : decimal ) + «set» DateSigned ( [in] value : DateTime ) + RevenueRecognition ( [in] dt : DateTime , [in] amt : decimal ) + «set» Revenue ( [in] value : decimal ) * A Workbench for Learning - _RevenueRecognitions Enterprise Patterns
  • 70. Object-oriented: CalculateRevenues : Actor1 / UI / c : Contract : IRevenueRecognitionStrategy : ContractMapper : DBFactory 1 : btnCalc_Click 2 : CalculateRevenueRecognitions ( ) 3 : CalculateRevenueRecognitions ( ) 4 : AddRecognition ( recognitionDate , amount ) foreach recognized revenue 5 : Save ( c ) 6 : CreateDBHelper ( ) 7 : new : IDBHelper 8 : BeginTransaction ( ) 9 : ExecuteTransactedNonQuery ( cmd ) 10 : ExecuteTransactedNonQuery ( foreach recognized revenue cmd ) 11 : CommitTransaction ( ) A Workbench for Learning 70 Enterprise Patterns
  • 71. Problems with domain model How to avoid networks of objects to be fully loaded into memory when only a few “fields” are necessary Lazy Load How to guarantee that there are no multiple in memory representations of the same “db entity” Identity Field Identity Map How to allow for variations of the same algorithm? Strategy To embed each recognition rule in the Domain model
  • 74. Session synopsis 74 Introduced the concept of Enterprise application Software pattern Software architecture Layered architectures Presented the sample problem Presented an overview of the rest of the seminar
  • 75. At this final stage [...] The patterns aren’t important. The forces in the problem domain and how to resolve them are. Christopher Alexander (1979)
  • 76. Patterns of Enterprise Applications (by Example) Paulo Sousa 76 ISEP/IP pag@isep.ipp.pt http://linkedin.com/in/pagsousa P
  • 78. Bibliography 78 Fowler, Martin. Patterns of Enterprise Application Architecture. Adisson- Wesley. Erich Gamma, Richard Helm, Ralph Johnson, John Vissides. Design patterns : elements of reusable object-oriented software. Adisson-Wesley. Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael Stal. Pattern-oriented Software Architecture: System of Patterns. Buschmann, F.; Henney, K. And Schmidt, D. (2007) Pattern-Oriented Software Architecture: A Pattern Language for Distributed Computing, Volume 4. Willey. Deepak Alur, John Crupi and Dan Malks. Core J2EE Patterns: Best Practices and Design Strategies. Prentice Hall / Sun Microsystems Press. http://java.sun.com/blueprints/corej2eepatterns/index.html Enterprise Solution Patterns Using Microsoft .NET. Microsoft Press. http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar y/en-us/dnpatterns/html/Esp.asp Designing Data Tier Components and Passing Data Through Tiers. Microsoft Patterns & Practices. http://msdn.microsoft.com/library/?url=/library/en- us/dnbda/html/BOAGag.asp?frame=true
  • 79. Bibliography 79 Domain logic and SQL. Martin Fowler. http://www.martinfowler.com/articles/dblogic.htm l Why extends is evil. Allen Holub http://www.javaworld.com/javaworld/jw-08- 2003/jw-0801-toolbox.html Why getter and setter methods are evil . Allen Holub http://www.javaworld.com/javaworld/jw-09- 2003/jw-0905-toolbox.html Domain logic and SQL. Martin Fowler. http://www.martinfowler.com/articles/dblogic.html Public vs. Published interfaces. Martin Fowler. http://www.martinfowler.com/ieeeSoftware/publi shed.pdf Don’t live with Broken windows http://www.artima.com/intv/fixit.html
  • 80. Pattern catalogs 80 GoF Design patterns (em C#) http://www.dofactory.com/Patterns/Patterns.aspx GoF & POSA Design patterns (em Java) http://www.vico.org/pages/PatronsDisseny.html Patterns of Enterprise Application architecture http://martinfowler.com/eaaCatalog/ Core J2EE Patterns http://www.corej2eepatterns.com Enterprise Solution Patterns Using Microsoft .NET. http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar y/en-us/dnpatterns/html/Esp.asp Patterns of Enterprise Application Integration http://www.enterpriseintegrationpatterns.com/ Enterprise Java Patterns @ The Server Side http://www.theserverside.com/patterns/index.tss Microsoft Data Patterns http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/librar y/en-us/dnpatterns/html/Dp.asp