SlideShare a Scribd company logo
1 of 100
Web applica*on architecture
Ilio Catallo - info@iliocatallo.it
Outline
• Layers of abstrac.on
• Domain model
• Service layer
• Persistence layer
• Presenta.on layer
Layers of abstrac-on
Layers
A layer is a discrete, orthogonal area of concern within an applica4on
Applica'ons are made of layers
Applica'ons are broken down into a series of layers, so that each
layer isolates a different type of concern
Web applica*ons are made of layers
For instance, the problem of persis&ng data is isolated in the
persistence layer
Web app. layers
Typically, Web applica-ons have four layers of abstrac-on
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Communica)on between layers
Communica)on between layers is from top to bo5om
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Execu&on flow through layers
Layers can help conceptualize the flow through an applica5on
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Layers are not physically isolated
Even if layers are conceptually isolated, they are not necessarily
physically isolated
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Flexibility & testability
Isola&ng concerns (e.g., data persistence) into separate layers
increases flexibility and testability
Flexibility
Flexibility is increased because implementa0ons of each layer can
vary independently
public class SQLMovieRepository implements MovieRepository {...}
public class CSVMovieRepository implements MovieRepository {...}
public class RESTMovieRepository implements MovieRepository {...}
Testability
Testability is increased because the low-coupling between areas
make it easier to test each part
public class MovieServiceTest {
@Test
public void moviesDirectedByTest() {
...
}
}
How to design a layer?
Designing layers
When designing a layer, we first try to iden3fy a clear API for it
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
List<Flight> findFlights(String queryString);
}
Designing layers
We then expose such an API through a Java interface
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
List<Flight> findFlights(String queryString);
}
Designing layers
The interface acts as the layer's contract
• It enforces correct layer usage
• It hides implementa6on details
Interfaces as layer contracts
Interfaces are the key enablers to build applica/ons with layers
Domain model
Domain model
The domain model is the most important layer in the applica/on,
as it contains the business logic of the applica/on
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Domain model
In other words, the domain model is the code representa,on of
the business problem we are trying to solve
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Domain objects
The domain model consists of a network of interconnected domain
objects
+-------+ +-------+
| | | |
| A +------> B |
| | | |
+---^---+ +---^---+
| |
| |
+---+---+ |
| | |
| C +----------+
| |
+-------+
Concepts
Each class in the domain model corresponds to a concept from the
applica2on problem domain
+-------+ +-------+
| | | |
| A +------> B |
| | | |
+---^---+ +---^---+
| |
| |
+---+---+ |
| | |
| C +----------+
| |
+-------+
Problem domain concepts
That is, domain objects are specific to the applica4on’s problem
domain
+-------+ +-------+
| | | |
| A +------> B |
| | | |
+---^---+ +---^---+
| |
| |
+---+---+ |
| | |
| C +----------+
| |
+-------+
Airline travel Web applica/on
For instance, concepts for an Airline travel app may include:
• Airport
• Flight
• FlightLeg
• SpecialDeal
Nouns of the applica0on
A popular technique to determine the domain model is to use the
nouns in use case descrip3ons as domain objects
+-------+ +-------+
| | | |
| A +------> B |
| | | |
+---^---+ +---^---+
| |
| |
+---+---+ |
| | |
| C +----------+
| |
+-------+
Nouns of the applica0on
In other words, the nouns that are used when describing the
problem domain suggest domain objects
+-------+ +-------+
| | | |
| A +------> B |
| | | |
+---^---+ +---^---+
| |
| |
+---+---+ |
| | |
| C +----------+
| |
+-------+
Airport class
public class Airport {
private String name;
private String airportCode;
public Airport(String name,
String airportCode) {...}
// other methods
}
FlightLeg class
public class FlightLeg {
private Airport departFrom;
private Date departOn;
private Airport arriveAt;
private Date arriveOn;
public FlightLeg(Airport departFrom,
Date departOn,
Airport arriveAt,
Date arriveOn) {...}
// other methods
}
Flight class
public class Flight {
private List<FlightLeg> legs;
private BigDecimal totalCost;
public Flight(List<FlightLeg> legs,
BigDecimal totalCost) {...}
public boolean isNonStop() {...}
public long getTotalTravelTime() {...}
// other methods
}
Airline travel Web applica/on
Hence, the resul-ng domain model is as follows:
+---------+ +---------+ +----------+
| |////| | | | |
| |////+-----> +------> |
| |////| | | | |
+---------+ +---------+ +----------+
Flight FlightLeg Airport
Domain model ≠ set of rela0onships
It is important to note that business logic does not mean just a set
of rela,onships between objects
+---------+ +---------+ +----------+
| |////| | | | |
| |////+-----> +------> |
| |////| | | | |
+---------+ +---------+ +----------+
Flight FlightLeg Airport
Domain objects have state and behavior
As well as storing data, a domain model object should implement
the business logic that operates on the data
+---------+ +---------+ +----------+
| |////| | | | |
| |////+-----> +------> |
| |////| | | | |
+---------+ +---------+ +----------+
Flight FlightLeg Airport
Domain objects have state and behavior
That is, domain objects should have both state and behavior
+---------+
| |////|
| |////|
+---------+
Flight
Assign behavior to domain objects
Calculated values and derived answers should be provided by the
object you are talking with
+---------+
| |////|
| |////|
+---------+
Flight
Assign behavior to domain objects
Examples:
• Calculated value: Flight.getTotalTravelTime()
• Derived answer: Flight.isNonStop()
Object-oriented features
Pu#ng the business logic inside the domain objects makes it
possible to harness the full power of OOP
Object-oriented features
Think about how to take advantage of object-oriented features to
help solve the business problem
• Inheritance
• Polymorphism
Anemic domain model
A domain model that contains only state and rela1onships (but no
behavior) is usually called an anemic domain model
Pervasivity
The domain model is a layer that largely permeates the other layers
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Ver$cality
The domain model is a ver$cal layer, as all the other layers have
dependencies on the domain model
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Centrality
That is, even though each layer is responsible for its own concern,
all the layers live to serve the domain model
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Independence
However, the domain model has no dependency on any other layer
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║┌────────────────────────────────┐
║ n ║│ │
║ ║│ Service layer │
║ m ║│ │
║ o ║└────────────────────────────────┘
║ d ║┌────────────────────────────────┐
║ e ║│ │
║ l ║│ Persistence layer │
║ ║│ │
╚══════╝└────────────────────────────────┘
Domain objects do not need injec/on
In general, the domain model will not need dependencies injected
+---------+ +---------+ +----------+
| |////| | | | |
| |////+-----> +------> |
| |////| | | | |
+---------+ +---------+ +----------+
Flight FlightLeg Airport
Service Layer
Service Layer
The service layer exposes the use cases of the applica1on
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │╔════════════════════════════════╗
│ n │║ ║
│ │║ Service layer ║
│ m │║ ║
│ o │╚════════════════════════════════╝
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Airline travel Web applica/on
FlightService implements two applica.on use cases
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
List<Flight> findFlights(String queryString);
}
Coordinator
The service layer coordinates calls to the domain objects
+------------------------------------------+
| |
+--+--+ |
| | |
| S | +-------+ +-------+ |
| e | | | | | |
| r +-------> A +------> B | |
| v | | | | | |
| i | +---+---+ +---^---+ |
| c | | | |
| e | | | |
| | | +---+---+ |
| l | +----------> | |
| a | | C | |
| y +----------------------> | |
| e | +-------+ |
| r | |
| | |
+--+--+ |
| |
+------------------------------------------+
Single entry point
The service layer is the single entry point for the business logic
+------------------------------------------+
| |
+--+--+ |
| | |
| S | +-------+ +-------+ |
| e | | | | | |
| r +-------> A +------> B | |
| v | | | | | |
| i | +---+---+ +---^---+ |
| c | | | |
| e | | | |
| | | +---+---+ |
| l | +----------> | |
| a | | C | |
| y +----------------------> | |
| e | +-------+ |
| r | |
| | |
+--+--+ |
| |
+------------------------------------------+
Façade pa(ern
That is, the service layer acts as a façade
+------------------------------------------+
| |
+--+--+ |
| | |
| S | +-------+ +-------+ |
| e | | | | | |
| r +-------> A +------> B | |
| v | | | | | |
| i | +---+---+ +---^---+ |
| c | | | |
| e | | | |
| | | +---+---+ |
| l | +----------> | |
| a | | C | |
| y +----------------------> | |
| e | +-------+ |
| r | |
| | |
+--+--+ |
| |
+------------------------------------------+
Exposing the service layer
The business logic can then be exposed in different ways
• Web applica+ons
• Web service
• Desktop applica+on
Exposing the service layer
This thanks to the fact that, no ma0er the means, it is always the
same business logic to be executed
Transac'onality
Ideally, each applica-on’s use case should represent a single
transac'onal unit of work that either succeeds or fails
Transac'onality
Since the service layer is the single entry-point, we can apply
security and transac+onal requirements
@Transactional
public class FlightServiceImpl implements FlightService {
...
}
Coarse grained & stateless
Each method in the service layer should be coarse grained and
stateless
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
List<Flight> findFlights(String queryString);
}
Coarse grained
Coarse grained: a single method call will accomplish the en1re use
case
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
...
}
Stateless
Stateless: calls to a service method do not create any state on the
object implemen4ng the service interface
public interface FlightService {
List<SpecialDeal> getSpecialDeals();
...
}
Service layer
The service layer should never have a dependency on the
presenta3on layer
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │╔════════════════════════════════╗
│ n │║ ║
│ │║ Service layer ║
│ m │║ ║
│ o │╚════════════════════════════════╝
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Service layer
However, the service layer depends on the persistence layer
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │╔════════════════════════════════╗
│ n │║ ║
│ │║ Service layer ║
│ m │║ ║
│ o │╚════════════════════════════════╝
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Persistence layer
Persistence layer
The persistence layer is responsible for interfacing with the
underlying persistence mechanism
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │╔════════════════════════════════╗
│ e │║ ║
│ l │║ Persistence layer ║
│ │║ ║
└──────┘╚════════════════════════════════╝
Persistence layer
The persistence layer knows how to store and retrieve domain
objects from the data store
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │╔════════════════════════════════╗
│ e │║ ║
│ l │║ Persistence layer ║
│ │║ ║
└──────┘╚════════════════════════════════╝
Persistence layer
It does so in such a way that the service layer does not know which
underlying data store is used
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │╔════════════════════════════════╗
│ e │║ ║
│ l │║ Persistence layer ║
│ │║ ║
└──────┘╚════════════════════════════════╝
Persistence concerns
That is, the persistence layer isolates the applica0on from changes
in the persistence mechanisms
┌──────┐┌────────────────────────────────┐
│ D ││ │
│ o ││ Presentation layer │
│ m ││ │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │╔════════════════════════════════╗
│ e │║ ║
│ l │║ Persistence layer ║
│ │║ ║
└──────┘╚════════════════════════════════╝
Airline travel Web applica/on
public interface AccountRepository {
Account findByUsername(String username);
Account findById(long id);
Account save(Account account);
}
Airline travel Web applica/on
public interface AccountRepository {
Optional<Account> findByUsername(String username);
Optional<Account> findById(long id);
Account save(Account account);
}
The service layer is a coordina0on layer
The service layer coordinates the persistence layer and the
domain model
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║╔════════════════════════════════╗
║ n ║║ ║
║ ║║ Service layer ║
║ m ║║ ║
║ o ║╚════════════════════════════════╝
║ d ║╔════════════════════════════════╗
║ e ║║ ║
║ l ║║ Persistence layer ║
║ ║║ ║
╚══════╝╚════════════════════════════════╝
Persis&ng domain objects
The service layer ensures that the appropriate domain objects are
loaded and persisted in the use case
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║╔════════════════════════════════╗
║ n ║║ ║
║ ║║ Service layer ║
║ m ║║ ║
║ o ║╚════════════════════════════════╝
║ d ║╔════════════════════════════════╗
║ e ║║ ║
║ l ║║ Persistence layer ║
║ ║║ ║
╚══════╝╚════════════════════════════════╝
Domain objects are unaware
The domain objects are un unaware of being persisted
╔══════╗┌────────────────────────────────┐
║ D ║│ │
║ o ║│ Presentation layer │
║ m ║│ │
║ a ║└────────────────────────────────┘
║ i ║╔════════════════════════════════╗
║ n ║║ ║
║ ║║ Service layer ║
║ m ║║ ║
║ o ║╚════════════════════════════════╝
║ d ║╔════════════════════════════════╗
║ e ║║ ║
║ l ║║ Persistence layer ║
║ ║║ ║
╚══════╝╚════════════════════════════════╝
Presenta(on layer
Presenta(on layer
We can further detail the architecture by spli3ng the presenta5on
layer into a Web layer and a user interface layer
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Web layer
The Web layer has two responsibili-es
• It acts as the glue between the service layer and HTTP
• It drives the user through the correct pages in the order
HTTP oddi(es
The HTTP world is populated with strange creatures
• Request parameters
• Headers
• Cookies
Web logic ≠ business logic
These aspects are not business logic specific, and thus should be
kept isolated from the service layer
Web logic ≠ business logic
It's on the Web layer to hide the details of the Web from the
business logic
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │╔════════════════════════════════╗
│ n │║ ║ HTTP request?
│ │║ Service layer ║ I don't know what
│ m │║ ║ you are talking
│ o │╚════════════════════════════════╝ about...
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
The Web layer is an integra0on layer
The Web layer converts the incoming HTTP requests to something
that can be handled by the service layer...
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │╔════════════════════════════════╗ Don't worry! I've
│ m │║ Web layer ║ got you covered
│ a │╚════════════════════════════════╝
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
The Web layer is an integra0on layer
...and then transforms the result from the service layer into a
response for the user interface
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │╔════════════════════════════════╗ Here's the data
│ m │║ Web layer ║ you need to
│ a │╚════════════════════════════════╝ render the UI!
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Exposing the use cases
The Web layer is an adapter that connects to the service layer and
exposes it to the end user
Exposing the use cases
That is, the Web layer exposes the use cases to the Web
Naviga&on logic
Apart serving as an adapter, the Web layer is also in charge of
handling the naviga&on logic
Naviga&on logic
That is, the Web layer drives the user through the correct pages in
the correct order
TODO Web applica-on
GET /todo
+----------------------------+
| |
| |
+-----v-----+ +-----+------+
| | | |
GET /todo | List of | GET /todo/:id | Individual |
+-----------> TODOS +----------------> TODO |
| | | |
+--+-------^+ +------------+
| |
| |
| |
| |
+-------+
POST /todo
Naviga&on logic
The naviga*on is bound to the Web layer only. There is no
naviga*on logic in the service layer or in the domain model
Naviga&on logic
By guiding the user through the site, the Web layer determines the
user experience
Thin layer
The Web layer is a thin layer
• It is just a bridge between the Web and the service layer
• It does not contain any business logic
Web layer’s dependencies
The Web layer depends on the service layer, to which it delegates
the actual processing
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │╔════════════════════════════════╗
│ m │║ Web layer ║
│ a │╚════════════════════════════════╝
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
Web layer’s dependencies
The Web layer depends on the domain model, in that informa5on
from the Web could be converted to domain objects
┌──────┐┌────────────────────────────────┐
│ ││ User interface layer │
│ D │└────────────────────────────────┘
│ o │╔════════════════════════════════╗
│ m │║ Web layer ║
│ a │╚════════════════════════════════╝
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User Interface layer
User Interface layer
The user interface layer is responsible for presen&ng the
applica3on to the end user
┌──────┐╔════════════════════════════════╗
│ │║ User interface layer ║
│ D │╚════════════════════════════════╝
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User Interface layer
The user interface layer renders the response generated by the
Web layer into the form requested by the user’s client
┌──────┐╔════════════════════════════════╗
│ │║ User interface layer ║
│ D │╚════════════════════════════════╝
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User Interface layer
For instance:
• A Web browser will probable request a HTML page
• A Web service may want an XML (or JSON) document
• Another client could request a PDF document
Many view technologies are available
There exists a plethora of of view technologies
• JSP pages
• JSF pages
• Handlebars
Many view technologies are available
However, the naviga/on logic and the need of calling the service
layer does not change with the specific view technology
Many view technologies are available
That is why the user interface and the web layer are split
┌──────┐╔════════════════════════════════╗
│ │║ User interface layer ║
│ D │╚════════════════════════════════╝
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User interface layer’s dependency
The user interface layer may depend on the domain model
┌──────┐╔════════════════════════════════╗
│ │║ User interface layer ║
│ D │╚════════════════════════════════╝
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User interface layer’s dependency
Indeed, it is o+en convenient to expose and render domain objects
┌──────┐╔════════════════════════════════╗
│ │║ User interface layer ║
│ D │╚════════════════════════════════╝
│ o │┌────────────────────────────────┐
│ m ││ Web layer │
│ a │└────────────────────────────────┘
│ i │┌────────────────────────────────┐
│ n ││ │
│ ││ Service layer │
│ m ││ │
│ o │└────────────────────────────────┘
│ d │┌────────────────────────────────┐
│ e ││ │
│ l ││ Persistence layer │
│ ││ │
└──────┘└────────────────────────────────┘
User interface layer’s dependency
This is useful when we start to use forms in our applica2on, as it
makes possible to objec*fy form fields directly into domain
objects
References
References
• S. Ladd, K. Donald, Expert Spring MVC and Web flows, Apress
PublicaBons
• M. Deinum, K. Serneels, Pro Spring MVC: with Web flows,
Apress PublicaBons
• Chris Richardson, POJOs in AcBon, Manning PublicaBons
References
• Mar%n Fowler, Anemic Domain Model
• StackOverflow, What Does it Mean to “Program to an Interface”?

More Related Content

What's hot

Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++Mihai Todor
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...Francesco Casalegno
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stalMichael Stal
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questionsFarag Zakaria
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpMichael Stal
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersRichard Thomson
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphismkiran Patel
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory ManagementAnil Bapat
 

What's hot (20)

Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
Modern C++
Modern C++Modern C++
Modern C++
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questions
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
What is c
What is cWhat is c
What is c
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C Theory
C TheoryC Theory
C Theory
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
 
C++11
C++11C++11
C++11
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 

More from Ilio Catallo

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryIlio Catallo
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++Ilio Catallo
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++Ilio Catallo
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++Ilio Catallo
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++Ilio Catallo
 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layersIlio Catallo
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web FormsIlio Catallo
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The BasicsIlio Catallo
 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To SpringIlio Catallo
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++Ilio Catallo
 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e RiferimentiIlio Catallo
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag LibraryIlio Catallo
 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Ilio Catallo
 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Ilio Catallo
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3Ilio Catallo
 
Community Detection
Community DetectionCommunity Detection
Community DetectionIlio Catallo
 
WWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectWWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectIlio Catallo
 

More from Ilio Catallo (20)

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layers
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web Forms
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To Spring
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
 
Array in C++
Array in C++Array in C++
Array in C++
 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e Riferimenti
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3
 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Community Detection
Community DetectionCommunity Detection
Community Detection
 
WWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectWWW12 - The CUbRIK Project
WWW12 - The CUbRIK Project
 

Recently uploaded

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxAneriPatwari
 

Recently uploaded (20)

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptx
 

Web Application Architecture Layers

  • 1. Web applica*on architecture Ilio Catallo - info@iliocatallo.it
  • 2. Outline • Layers of abstrac.on • Domain model • Service layer • Persistence layer • Presenta.on layer
  • 4. Layers A layer is a discrete, orthogonal area of concern within an applica4on
  • 5. Applica'ons are made of layers Applica'ons are broken down into a series of layers, so that each layer isolates a different type of concern
  • 6. Web applica*ons are made of layers For instance, the problem of persis&ng data is isolated in the persistence layer
  • 7. Web app. layers Typically, Web applica-ons have four layers of abstrac-on ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 8. Communica)on between layers Communica)on between layers is from top to bo5om ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 9. Execu&on flow through layers Layers can help conceptualize the flow through an applica5on ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 10. Layers are not physically isolated Even if layers are conceptually isolated, they are not necessarily physically isolated ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 11. Flexibility & testability Isola&ng concerns (e.g., data persistence) into separate layers increases flexibility and testability
  • 12. Flexibility Flexibility is increased because implementa0ons of each layer can vary independently public class SQLMovieRepository implements MovieRepository {...} public class CSVMovieRepository implements MovieRepository {...} public class RESTMovieRepository implements MovieRepository {...}
  • 13. Testability Testability is increased because the low-coupling between areas make it easier to test each part public class MovieServiceTest { @Test public void moviesDirectedByTest() { ... } }
  • 14. How to design a layer?
  • 15. Designing layers When designing a layer, we first try to iden3fy a clear API for it public interface FlightService { List<SpecialDeal> getSpecialDeals(); List<Flight> findFlights(String queryString); }
  • 16. Designing layers We then expose such an API through a Java interface public interface FlightService { List<SpecialDeal> getSpecialDeals(); List<Flight> findFlights(String queryString); }
  • 17. Designing layers The interface acts as the layer's contract • It enforces correct layer usage • It hides implementa6on details
  • 18. Interfaces as layer contracts Interfaces are the key enablers to build applica/ons with layers
  • 20. Domain model The domain model is the most important layer in the applica/on, as it contains the business logic of the applica/on ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 21. Domain model In other words, the domain model is the code representa,on of the business problem we are trying to solve ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 22. Domain objects The domain model consists of a network of interconnected domain objects +-------+ +-------+ | | | | | A +------> B | | | | | +---^---+ +---^---+ | | | | +---+---+ | | | | | C +----------+ | | +-------+
  • 23. Concepts Each class in the domain model corresponds to a concept from the applica2on problem domain +-------+ +-------+ | | | | | A +------> B | | | | | +---^---+ +---^---+ | | | | +---+---+ | | | | | C +----------+ | | +-------+
  • 24. Problem domain concepts That is, domain objects are specific to the applica4on’s problem domain +-------+ +-------+ | | | | | A +------> B | | | | | +---^---+ +---^---+ | | | | +---+---+ | | | | | C +----------+ | | +-------+
  • 25. Airline travel Web applica/on For instance, concepts for an Airline travel app may include: • Airport • Flight • FlightLeg • SpecialDeal
  • 26. Nouns of the applica0on A popular technique to determine the domain model is to use the nouns in use case descrip3ons as domain objects +-------+ +-------+ | | | | | A +------> B | | | | | +---^---+ +---^---+ | | | | +---+---+ | | | | | C +----------+ | | +-------+
  • 27. Nouns of the applica0on In other words, the nouns that are used when describing the problem domain suggest domain objects +-------+ +-------+ | | | | | A +------> B | | | | | +---^---+ +---^---+ | | | | +---+---+ | | | | | C +----------+ | | +-------+
  • 28. Airport class public class Airport { private String name; private String airportCode; public Airport(String name, String airportCode) {...} // other methods }
  • 29. FlightLeg class public class FlightLeg { private Airport departFrom; private Date departOn; private Airport arriveAt; private Date arriveOn; public FlightLeg(Airport departFrom, Date departOn, Airport arriveAt, Date arriveOn) {...} // other methods }
  • 30. Flight class public class Flight { private List<FlightLeg> legs; private BigDecimal totalCost; public Flight(List<FlightLeg> legs, BigDecimal totalCost) {...} public boolean isNonStop() {...} public long getTotalTravelTime() {...} // other methods }
  • 31. Airline travel Web applica/on Hence, the resul-ng domain model is as follows: +---------+ +---------+ +----------+ | |////| | | | | | |////+-----> +------> | | |////| | | | | +---------+ +---------+ +----------+ Flight FlightLeg Airport
  • 32. Domain model ≠ set of rela0onships It is important to note that business logic does not mean just a set of rela,onships between objects +---------+ +---------+ +----------+ | |////| | | | | | |////+-----> +------> | | |////| | | | | +---------+ +---------+ +----------+ Flight FlightLeg Airport
  • 33. Domain objects have state and behavior As well as storing data, a domain model object should implement the business logic that operates on the data +---------+ +---------+ +----------+ | |////| | | | | | |////+-----> +------> | | |////| | | | | +---------+ +---------+ +----------+ Flight FlightLeg Airport
  • 34. Domain objects have state and behavior That is, domain objects should have both state and behavior +---------+ | |////| | |////| +---------+ Flight
  • 35. Assign behavior to domain objects Calculated values and derived answers should be provided by the object you are talking with +---------+ | |////| | |////| +---------+ Flight
  • 36. Assign behavior to domain objects Examples: • Calculated value: Flight.getTotalTravelTime() • Derived answer: Flight.isNonStop()
  • 37. Object-oriented features Pu#ng the business logic inside the domain objects makes it possible to harness the full power of OOP
  • 38. Object-oriented features Think about how to take advantage of object-oriented features to help solve the business problem • Inheritance • Polymorphism
  • 39. Anemic domain model A domain model that contains only state and rela1onships (but no behavior) is usually called an anemic domain model
  • 40. Pervasivity The domain model is a layer that largely permeates the other layers ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 41. Ver$cality The domain model is a ver$cal layer, as all the other layers have dependencies on the domain model ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 42. Centrality That is, even though each layer is responsible for its own concern, all the layers live to serve the domain model ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 43. Independence However, the domain model has no dependency on any other layer ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║┌────────────────────────────────┐ ║ n ║│ │ ║ ║│ Service layer │ ║ m ║│ │ ║ o ║└────────────────────────────────┘ ║ d ║┌────────────────────────────────┐ ║ e ║│ │ ║ l ║│ Persistence layer │ ║ ║│ │ ╚══════╝└────────────────────────────────┘
  • 44. Domain objects do not need injec/on In general, the domain model will not need dependencies injected +---------+ +---------+ +----------+ | |////| | | | | | |////+-----> +------> | | |////| | | | | +---------+ +---------+ +----------+ Flight FlightLeg Airport
  • 46. Service Layer The service layer exposes the use cases of the applica1on ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │╔════════════════════════════════╗ │ n │║ ║ │ │║ Service layer ║ │ m │║ ║ │ o │╚════════════════════════════════╝ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 47. Airline travel Web applica/on FlightService implements two applica.on use cases public interface FlightService { List<SpecialDeal> getSpecialDeals(); List<Flight> findFlights(String queryString); }
  • 48. Coordinator The service layer coordinates calls to the domain objects +------------------------------------------+ | | +--+--+ | | | | | S | +-------+ +-------+ | | e | | | | | | | r +-------> A +------> B | | | v | | | | | | | i | +---+---+ +---^---+ | | c | | | | | e | | | | | | | +---+---+ | | l | +----------> | | | a | | C | | | y +----------------------> | | | e | +-------+ | | r | | | | | +--+--+ | | | +------------------------------------------+
  • 49. Single entry point The service layer is the single entry point for the business logic +------------------------------------------+ | | +--+--+ | | | | | S | +-------+ +-------+ | | e | | | | | | | r +-------> A +------> B | | | v | | | | | | | i | +---+---+ +---^---+ | | c | | | | | e | | | | | | | +---+---+ | | l | +----------> | | | a | | C | | | y +----------------------> | | | e | +-------+ | | r | | | | | +--+--+ | | | +------------------------------------------+
  • 50. Façade pa(ern That is, the service layer acts as a façade +------------------------------------------+ | | +--+--+ | | | | | S | +-------+ +-------+ | | e | | | | | | | r +-------> A +------> B | | | v | | | | | | | i | +---+---+ +---^---+ | | c | | | | | e | | | | | | | +---+---+ | | l | +----------> | | | a | | C | | | y +----------------------> | | | e | +-------+ | | r | | | | | +--+--+ | | | +------------------------------------------+
  • 51. Exposing the service layer The business logic can then be exposed in different ways • Web applica+ons • Web service • Desktop applica+on
  • 52. Exposing the service layer This thanks to the fact that, no ma0er the means, it is always the same business logic to be executed
  • 53. Transac'onality Ideally, each applica-on’s use case should represent a single transac'onal unit of work that either succeeds or fails
  • 54. Transac'onality Since the service layer is the single entry-point, we can apply security and transac+onal requirements @Transactional public class FlightServiceImpl implements FlightService { ... }
  • 55. Coarse grained & stateless Each method in the service layer should be coarse grained and stateless public interface FlightService { List<SpecialDeal> getSpecialDeals(); List<Flight> findFlights(String queryString); }
  • 56. Coarse grained Coarse grained: a single method call will accomplish the en1re use case public interface FlightService { List<SpecialDeal> getSpecialDeals(); ... }
  • 57. Stateless Stateless: calls to a service method do not create any state on the object implemen4ng the service interface public interface FlightService { List<SpecialDeal> getSpecialDeals(); ... }
  • 58. Service layer The service layer should never have a dependency on the presenta3on layer ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │╔════════════════════════════════╗ │ n │║ ║ │ │║ Service layer ║ │ m │║ ║ │ o │╚════════════════════════════════╝ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 59. Service layer However, the service layer depends on the persistence layer ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │╔════════════════════════════════╗ │ n │║ ║ │ │║ Service layer ║ │ m │║ ║ │ o │╚════════════════════════════════╝ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 61. Persistence layer The persistence layer is responsible for interfacing with the underlying persistence mechanism ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │╔════════════════════════════════╗ │ e │║ ║ │ l │║ Persistence layer ║ │ │║ ║ └──────┘╚════════════════════════════════╝
  • 62. Persistence layer The persistence layer knows how to store and retrieve domain objects from the data store ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │╔════════════════════════════════╗ │ e │║ ║ │ l │║ Persistence layer ║ │ │║ ║ └──────┘╚════════════════════════════════╝
  • 63. Persistence layer It does so in such a way that the service layer does not know which underlying data store is used ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │╔════════════════════════════════╗ │ e │║ ║ │ l │║ Persistence layer ║ │ │║ ║ └──────┘╚════════════════════════════════╝
  • 64. Persistence concerns That is, the persistence layer isolates the applica0on from changes in the persistence mechanisms ┌──────┐┌────────────────────────────────┐ │ D ││ │ │ o ││ Presentation layer │ │ m ││ │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │╔════════════════════════════════╗ │ e │║ ║ │ l │║ Persistence layer ║ │ │║ ║ └──────┘╚════════════════════════════════╝
  • 65. Airline travel Web applica/on public interface AccountRepository { Account findByUsername(String username); Account findById(long id); Account save(Account account); }
  • 66. Airline travel Web applica/on public interface AccountRepository { Optional<Account> findByUsername(String username); Optional<Account> findById(long id); Account save(Account account); }
  • 67. The service layer is a coordina0on layer The service layer coordinates the persistence layer and the domain model ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║╔════════════════════════════════╗ ║ n ║║ ║ ║ ║║ Service layer ║ ║ m ║║ ║ ║ o ║╚════════════════════════════════╝ ║ d ║╔════════════════════════════════╗ ║ e ║║ ║ ║ l ║║ Persistence layer ║ ║ ║║ ║ ╚══════╝╚════════════════════════════════╝
  • 68. Persis&ng domain objects The service layer ensures that the appropriate domain objects are loaded and persisted in the use case ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║╔════════════════════════════════╗ ║ n ║║ ║ ║ ║║ Service layer ║ ║ m ║║ ║ ║ o ║╚════════════════════════════════╝ ║ d ║╔════════════════════════════════╗ ║ e ║║ ║ ║ l ║║ Persistence layer ║ ║ ║║ ║ ╚══════╝╚════════════════════════════════╝
  • 69. Domain objects are unaware The domain objects are un unaware of being persisted ╔══════╗┌────────────────────────────────┐ ║ D ║│ │ ║ o ║│ Presentation layer │ ║ m ║│ │ ║ a ║└────────────────────────────────┘ ║ i ║╔════════════════════════════════╗ ║ n ║║ ║ ║ ║║ Service layer ║ ║ m ║║ ║ ║ o ║╚════════════════════════════════╝ ║ d ║╔════════════════════════════════╗ ║ e ║║ ║ ║ l ║║ Persistence layer ║ ║ ║║ ║ ╚══════╝╚════════════════════════════════╝
  • 71. Presenta(on layer We can further detail the architecture by spli3ng the presenta5on layer into a Web layer and a user interface layer ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 72. Web layer The Web layer has two responsibili-es • It acts as the glue between the service layer and HTTP • It drives the user through the correct pages in the order
  • 73. HTTP oddi(es The HTTP world is populated with strange creatures • Request parameters • Headers • Cookies
  • 74. Web logic ≠ business logic These aspects are not business logic specific, and thus should be kept isolated from the service layer
  • 75. Web logic ≠ business logic It's on the Web layer to hide the details of the Web from the business logic ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │╔════════════════════════════════╗ │ n │║ ║ HTTP request? │ │║ Service layer ║ I don't know what │ m │║ ║ you are talking │ o │╚════════════════════════════════╝ about... │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 76. The Web layer is an integra0on layer The Web layer converts the incoming HTTP requests to something that can be handled by the service layer... ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │╔════════════════════════════════╗ Don't worry! I've │ m │║ Web layer ║ got you covered │ a │╚════════════════════════════════╝ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 77. The Web layer is an integra0on layer ...and then transforms the result from the service layer into a response for the user interface ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │╔════════════════════════════════╗ Here's the data │ m │║ Web layer ║ you need to │ a │╚════════════════════════════════╝ render the UI! │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 78. Exposing the use cases The Web layer is an adapter that connects to the service layer and exposes it to the end user
  • 79. Exposing the use cases That is, the Web layer exposes the use cases to the Web
  • 80. Naviga&on logic Apart serving as an adapter, the Web layer is also in charge of handling the naviga&on logic
  • 81. Naviga&on logic That is, the Web layer drives the user through the correct pages in the correct order
  • 82. TODO Web applica-on GET /todo +----------------------------+ | | | | +-----v-----+ +-----+------+ | | | | GET /todo | List of | GET /todo/:id | Individual | +-----------> TODOS +----------------> TODO | | | | | +--+-------^+ +------------+ | | | | | | | | +-------+ POST /todo
  • 83. Naviga&on logic The naviga*on is bound to the Web layer only. There is no naviga*on logic in the service layer or in the domain model
  • 84. Naviga&on logic By guiding the user through the site, the Web layer determines the user experience
  • 85. Thin layer The Web layer is a thin layer • It is just a bridge between the Web and the service layer • It does not contain any business logic
  • 86. Web layer’s dependencies The Web layer depends on the service layer, to which it delegates the actual processing ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │╔════════════════════════════════╗ │ m │║ Web layer ║ │ a │╚════════════════════════════════╝ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 87. Web layer’s dependencies The Web layer depends on the domain model, in that informa5on from the Web could be converted to domain objects ┌──────┐┌────────────────────────────────┐ │ ││ User interface layer │ │ D │└────────────────────────────────┘ │ o │╔════════════════════════════════╗ │ m │║ Web layer ║ │ a │╚════════════════════════════════╝ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 89. User Interface layer The user interface layer is responsible for presen&ng the applica3on to the end user ┌──────┐╔════════════════════════════════╗ │ │║ User interface layer ║ │ D │╚════════════════════════════════╝ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 90. User Interface layer The user interface layer renders the response generated by the Web layer into the form requested by the user’s client ┌──────┐╔════════════════════════════════╗ │ │║ User interface layer ║ │ D │╚════════════════════════════════╝ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 91. User Interface layer For instance: • A Web browser will probable request a HTML page • A Web service may want an XML (or JSON) document • Another client could request a PDF document
  • 92. Many view technologies are available There exists a plethora of of view technologies • JSP pages • JSF pages • Handlebars
  • 93. Many view technologies are available However, the naviga/on logic and the need of calling the service layer does not change with the specific view technology
  • 94. Many view technologies are available That is why the user interface and the web layer are split ┌──────┐╔════════════════════════════════╗ │ │║ User interface layer ║ │ D │╚════════════════════════════════╝ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 95. User interface layer’s dependency The user interface layer may depend on the domain model ┌──────┐╔════════════════════════════════╗ │ │║ User interface layer ║ │ D │╚════════════════════════════════╝ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 96. User interface layer’s dependency Indeed, it is o+en convenient to expose and render domain objects ┌──────┐╔════════════════════════════════╗ │ │║ User interface layer ║ │ D │╚════════════════════════════════╝ │ o │┌────────────────────────────────┐ │ m ││ Web layer │ │ a │└────────────────────────────────┘ │ i │┌────────────────────────────────┐ │ n ││ │ │ ││ Service layer │ │ m ││ │ │ o │└────────────────────────────────┘ │ d │┌────────────────────────────────┐ │ e ││ │ │ l ││ Persistence layer │ │ ││ │ └──────┘└────────────────────────────────┘
  • 97. User interface layer’s dependency This is useful when we start to use forms in our applica2on, as it makes possible to objec*fy form fields directly into domain objects
  • 99. References • S. Ladd, K. Donald, Expert Spring MVC and Web flows, Apress PublicaBons • M. Deinum, K. Serneels, Pro Spring MVC: with Web flows, Apress PublicaBons • Chris Richardson, POJOs in AcBon, Manning PublicaBons
  • 100. References • Mar%n Fowler, Anemic Domain Model • StackOverflow, What Does it Mean to “Program to an Interface”?