3 Layers
Based on the Presentation Domain Data Layer, Fowler, a 3-layer application consists of:
- presentation
- business
- access to resources/data
With this architecture, it focuses on the information to be rendered/presented, the information to be operated and the information to be saved/rescued.
Note that the database is not part of this architecture, but rather the access to the bank.
Fowler considers and defends (in general) the use of this architecture for a simple question: scope of attention. The team in the presentation layer is not too concerned about what is happening in the business layer, so for them just know how to display the data provided through a previously determined API.
The business team will not need to worry about how the information will be displayed, nor how it will be persisted/rescued, focusing merely on manipulating the information correctly and giving the correct result. People on this team need to have a known API to request resources or to have them persist, and only need to know this from the resource/data layer.
The persistence layer team does not need to worry whether the calculations will be done in the right way, just know how to assemble the requested data or save it. The option to save to a temporarily embedded database, keep in memory, or even send to the perennial database is a concern of this layer.
Fowler himself, describing the behavior of a euquipe working in these 3 layers (free translation):
When I’m working on [layer of] presentation I can focus on UI behavior, treating any data to be shown or updated as magically appearing through function calls. By separating these elements I funnel the scope of my thinking into each piece, p that makes it easier for me to give continuity to what I need to do.
Even though there is occasionally some development cross-Section (cutting by multiple layers), incremental development becomes more natural. Imagine that you are making a sales application and, when you are doing the interface, you come across "puts, I forgot the ICMS-ST". Thus, the presentation layer leaves a little box ready to receive an arbitrary data with the value of this tax (which eventually modifies the value of buying but does not modify the sale). So, with that ready, he can worry about rescuing from the bank correctly the rates of this tax and its tariff value, to then, in the business layer, decide if the data are favorable to use rate or tariff and make the relevant calculations, delivering to the presentation layer a round die.
Note that this type of 3-layer architecture does not impose where this processing should take place. For example, where I work, we use GWT. We write in Java and in an XML dialect called ui.xml
the presentation layer, and the GWT magically transforms it into Javascript and sends it to the client. The business layer is usually in a dependency part, which internally we call core of the system.
If you want to read more, I wrote an article on Medium which also deals with this
The kernel is all written in Java and made to run as Java Web, compatible (in the strictly necessary part) with GWT serialization and compatible with Totalcross.
We are leaving it viable for Android too, soon I will write an article on the subject
In addition to the core, where the validations of business rules occur, we also have a layer that we call DAO
(or I-DAO
, there is a pseudolayer M-DAO
) by force of habit. This layer, implemented by the application that calls the nucleus, is concerned only with assembling the data to give them to the nucleus or saving the data coming from the nucleus. The only thing that matters to the kernel is that it can call through Java and that they are synchronous methods (choose this questionable, but there was not much support for asynchrony in Totalcross).
In the Totalcross implementation of this layer, it is basically written in Java with TCDBC (like JDBC, but Totalcross; too similar, but has some differences that require a lot of attention). In the Java Web implementation (irrelevant whether GWT or not), we have to DAO
written in Java chews the data to call Mybatis optimally, without the queries written in the Mybatis way of being that mixes an XML dialect and "text" in SQL within the tags. Sometimes it is preferable in this layer to turn the business object into another data transport that is easier to handle with Mybatis, as well as to recover transport objects to mount them properly after calling the database.
This separation allowed a much more optimized work of the team, especially in the GWT part. The GWT part was rewritten from scratch, totally abandoning the old GWT part in order to update technology (like Mybatis, which was previously iBatis) and removing the business rules from the presentation layer. Legacy GWT code still made a lot of business rule in the presentation layer.
In the Totalcross part, however, there was no full rewrite. In fact, from this part was extracted the nucleus in an experimental and exploratory way and we were gradually adapting some parts extracted to communicate with the nucleus, but punctually and with the whole load of a legacy giant code on the back. There is still a lot of business rule in the layers that should be concerned only with data presentation, especially on low customization screens and with low incidence of reported bugs.
Legacy code and the "disharmonious" part of the city.
We have another "application" at work that, in fact, there is no business rule. It is only the implementation of a communication protocol designed to meet the limitations provided by Totalcross at the time, the TJ protocol.
The implementation of this protocol consists of a client and a server, but does not determine the function of each one. We have the case that both client and server are able to write and read in this protocol. Other cases where only writing happens, others where only reading happens.
When sending data, the application is composed only of a thin layer of access to the bank to retrieve the information to be sent and a presenter, which will envelop the ResultSet
in a JSON. In receiving data, which by the TJ protocol needs to be much complacent, there is only the reading of what was presented and sends to the database upsert or delete of the corresponding line, therefore there is the need to implement a thin layer of introspection of the tables and a layer of assembly of the upsert.
Thus, these "applications" that implement TJ sending can be analyzed through the 3 layers, where there is only concern with presentation and rescue. The implementation of the receipt, in turn, has no data presentation, only the parse (maybe someone considers business layer? ) and persistence.
Client-server
The architecture client-server is independent of 3-layer architecture. In the traditional client-server architecture, you have an application that is listening (the server) and another that eventually makes a request.
In this architecture, who indicates that wants communication is the client. A server is only able to send some data to the client when it is connected.
The HTTP 1.0 model is an example of client-server architecture, where the client (usually the browser) asks for a resource (a web page) for the server. When the communication ends, the two say goodbye and goodbye, only if there is another request from the client to send data.
But not all client-server communication needs to be like this, just the client pushing data. SSH is also client-server, in which case the command top
, when typed from the client terminal, starts the executable top
which is constantly updating the client with the resource consumption information of the machine on which the server is located. The watch
also causes the server to send data without having to be explicitly bothered by the client.
In my work, we turn more strongly the client-server architecture precisely in the applications that work with the TJ protocol. We have a client written in ADVPL to run in Erps Protheus able to present the data in TJ format, as well as read the information and decide how to persist them in Protheus. But our server was written client independent, accepting to be plugged by other Erps, testable via HTTP request.
I did not have prior access to SWEBOK, this may have caused the confusion well explained by you. I will study some more and revise my answer. And in the meantime read your updated answer =D
– Jefferson Quesado