Layered Architecture

Lars-Erik Kindblad
Senior Consultant
Blog: kindblad.com
Agenda
   Logical Layer Architecture
   Example Code
   Physical Tier Architecture
   Logical Layer vs Physical Tier Architecture
   Summary
   Questions




                                                  | Sector, Alliance, Offering
LOGICAL LAYER ARCHITECTURE

                             | Sector, Alliance, Offering
3-Layer Architecture




                       | Sector, Alliance, Offering
Presentation Layer
 Also known as Frontend Layer, User Interface (UI) Layer

 Responsible for creating and displaying the user interface and
  handling user interaction
 Data shown is fetched from the Domain Layer




                                                            | Sector, Alliance, Offering
Service Layer
 Also known as Web Service Layer

 Responsible for exposing a web service API and returning the
  method result as XML or JSON
 Data returned is retrieved from the Domain Layer




                                                          | Sector, Alliance, Offering
Domain Layer
 Also known as Business Layer

 Responsible for all the business logic in the application
 Consists of a Domain Model and Domain Services




                                                              | Sector, Alliance, Offering
Domain Model
 Also known as Business Model, Business Objects, Entities etc.

 Responsible for having a model that reflects how the business
  stakeholders look at the world
 Consists of entities with relationships and behavior
 Similar to a database model but a domain model is richer




                                                          | Sector, Alliance, Offering
Domain Service
 Also known as Business Services, Business Managers etc.

 Business logic that does not belong within an entity




                                                         | Sector, Alliance, Offering
Infrastructure Layer
 Also known as Data Access Layer, Repository Layer etc.

 Responsible for querying a database, calling a web service, sending
  e-mail etc.




                                                           | Sector, Alliance, Offering
Example

 We want to create a banking application with customers and related
  accounts. An account consist of an account number, a balance and
  a credit limit.
  If the account has been overdrawn then the account and customer is
  considered to be “sick”, otherwise “healthy”

 Use Case 1: As a user I want to see if a customer is healthy or sick
 Use Case 2: As a user I want to retrieve if a customer is healthy or
  sick through a web service

 Technology: .NET, ASP.NET MVC, WCF

                                                            | Sector, Alliance, Offering
What do we need?

1. Domain Model for Customer and Account
2. Business logic for deciding if an account and customer is healthy or
   sick
3. 2 Classes: Fetching Customer and fetch list of Accounts from the
   database
4. Service Class for building up a Customer Entity with Accounts
Use Case 1:
1. MVC Controller and a View to display the health status for a given
   customer
Use Case 2:
1. WCF Service for returning whether a customer is healthy or not
                                                            | Sector, Alliance, Offering
Domain Model




               | Sector, Alliance, Offering
Domain Model




               | Sector, Alliance, Offering
Progress




           | Sector, Alliance, Offering
Infrastructure – Fetch Customer




                                  | Sector, Alliance, Offering
Infrastructure – Fetch Accounts




                                  | Sector, Alliance, Offering
Progress




           | Sector, Alliance, Offering
Domain Service – Build a Complete Customer




                                             | Sector, Alliance, Offering
Progress




           | Sector, Alliance, Offering
Use Case 1: Show the result to the user




                                          | Sector, Alliance, Offering
Progress




           | Sector, Alliance, Offering
Use Case 2: Return the result through a Web Service




                                               | Sector, Alliance, Offering
Completed




            | Sector, Alliance, Offering
Visual Studio Project Structure




                                  | Sector, Alliance, Offering
Why should you have many layers?

   Less code per layer
   Reduced complexity
   Easier to maintain code
   Easier to add new functionality
   Easier to test
   Allows for reuse code across the application




                                                   | Sector, Alliance, Offering
PHYSICAL TIER ARCHITECTURE

                             | Sector, Alliance, Offering
Logical Layer vs Physical Tier
 A Logically Layer is how you logically divide the code in the
  application
 A Physical Tier is how you divide your application into multiple sub-
  applications that can run on separate servers




                                                             | Sector, Alliance, Offering
2-Tier Windows Client Architecture




                                     | Sector, Alliance, Offering
3-Tier Windows Client Architecture




                                     | Sector, Alliance, Offering
3-Tier Web Architecture




                          | Sector, Alliance, Offering
4-Tier Architecture




                      | Sector, Alliance, Offering
Why have many tiers?
 Reuse logic across applications
 Improve security, e.g. restrict database access for the client by going
  through a service
 Improved performance, the performance critical tiers can be scaled
  across multiple servers




                                                              | Sector, Alliance, Offering
Summary
 Logical Layers
  • How you logically divide the code in the application
  • Three Layer Architecture is most common
    o Presentation Layer or Service Layer
    o Domain Layer with a Domain Model and Domain Services
    o Infrastructure layer for communicating with data sources
 Physical Tiers
  • How you divide the application into many sub-applications




                                                                 | Sector, Alliance, Offering
QUESTIONS?

             | Sector, Alliance, Offering
www.capgemini.com



The information contained in this presentation is proprietary. ©2010 Capgemini. All rights reserved

Layered Software Architecture

  • 1.
  • 2.
    Agenda  Logical Layer Architecture  Example Code  Physical Tier Architecture  Logical Layer vs Physical Tier Architecture  Summary  Questions | Sector, Alliance, Offering
  • 3.
    LOGICAL LAYER ARCHITECTURE | Sector, Alliance, Offering
  • 4.
    3-Layer Architecture | Sector, Alliance, Offering
  • 5.
    Presentation Layer  Alsoknown as Frontend Layer, User Interface (UI) Layer  Responsible for creating and displaying the user interface and handling user interaction  Data shown is fetched from the Domain Layer | Sector, Alliance, Offering
  • 6.
    Service Layer  Alsoknown as Web Service Layer  Responsible for exposing a web service API and returning the method result as XML or JSON  Data returned is retrieved from the Domain Layer | Sector, Alliance, Offering
  • 7.
    Domain Layer  Alsoknown as Business Layer  Responsible for all the business logic in the application  Consists of a Domain Model and Domain Services | Sector, Alliance, Offering
  • 8.
    Domain Model  Alsoknown as Business Model, Business Objects, Entities etc.  Responsible for having a model that reflects how the business stakeholders look at the world  Consists of entities with relationships and behavior  Similar to a database model but a domain model is richer | Sector, Alliance, Offering
  • 9.
    Domain Service  Alsoknown as Business Services, Business Managers etc.  Business logic that does not belong within an entity | Sector, Alliance, Offering
  • 10.
    Infrastructure Layer  Alsoknown as Data Access Layer, Repository Layer etc.  Responsible for querying a database, calling a web service, sending e-mail etc. | Sector, Alliance, Offering
  • 11.
    Example  We wantto create a banking application with customers and related accounts. An account consist of an account number, a balance and a credit limit. If the account has been overdrawn then the account and customer is considered to be “sick”, otherwise “healthy”  Use Case 1: As a user I want to see if a customer is healthy or sick  Use Case 2: As a user I want to retrieve if a customer is healthy or sick through a web service  Technology: .NET, ASP.NET MVC, WCF | Sector, Alliance, Offering
  • 12.
    What do weneed? 1. Domain Model for Customer and Account 2. Business logic for deciding if an account and customer is healthy or sick 3. 2 Classes: Fetching Customer and fetch list of Accounts from the database 4. Service Class for building up a Customer Entity with Accounts Use Case 1: 1. MVC Controller and a View to display the health status for a given customer Use Case 2: 1. WCF Service for returning whether a customer is healthy or not | Sector, Alliance, Offering
  • 13.
    Domain Model | Sector, Alliance, Offering
  • 14.
    Domain Model | Sector, Alliance, Offering
  • 15.
    Progress | Sector, Alliance, Offering
  • 16.
    Infrastructure – FetchCustomer | Sector, Alliance, Offering
  • 17.
    Infrastructure – FetchAccounts | Sector, Alliance, Offering
  • 18.
    Progress | Sector, Alliance, Offering
  • 19.
    Domain Service –Build a Complete Customer | Sector, Alliance, Offering
  • 20.
    Progress | Sector, Alliance, Offering
  • 21.
    Use Case 1:Show the result to the user | Sector, Alliance, Offering
  • 22.
    Progress | Sector, Alliance, Offering
  • 23.
    Use Case 2:Return the result through a Web Service | Sector, Alliance, Offering
  • 24.
    Completed | Sector, Alliance, Offering
  • 25.
    Visual Studio ProjectStructure | Sector, Alliance, Offering
  • 26.
    Why should youhave many layers?  Less code per layer  Reduced complexity  Easier to maintain code  Easier to add new functionality  Easier to test  Allows for reuse code across the application | Sector, Alliance, Offering
  • 27.
    PHYSICAL TIER ARCHITECTURE | Sector, Alliance, Offering
  • 28.
    Logical Layer vsPhysical Tier  A Logically Layer is how you logically divide the code in the application  A Physical Tier is how you divide your application into multiple sub- applications that can run on separate servers | Sector, Alliance, Offering
  • 29.
    2-Tier Windows ClientArchitecture | Sector, Alliance, Offering
  • 30.
    3-Tier Windows ClientArchitecture | Sector, Alliance, Offering
  • 31.
    3-Tier Web Architecture | Sector, Alliance, Offering
  • 32.
    4-Tier Architecture | Sector, Alliance, Offering
  • 33.
    Why have manytiers?  Reuse logic across applications  Improve security, e.g. restrict database access for the client by going through a service  Improved performance, the performance critical tiers can be scaled across multiple servers | Sector, Alliance, Offering
  • 34.
    Summary  Logical Layers • How you logically divide the code in the application • Three Layer Architecture is most common o Presentation Layer or Service Layer o Domain Layer with a Domain Model and Domain Services o Infrastructure layer for communicating with data sources  Physical Tiers • How you divide the application into many sub-applications | Sector, Alliance, Offering
  • 35.
    QUESTIONS? | Sector, Alliance, Offering
  • 36.
    www.capgemini.com The information containedin this presentation is proprietary. ©2010 Capgemini. All rights reserved