Layered architecture. Definition and tasks

      Comments Off on Layered architecture. Definition and tasks

Home Forums Programming Software engineering Patterns design Layered architecture. Definition and tasks

This topic contains 0 replies, has 1 voice, and was last updated by  Васильев Владимир Сергеевич 3 months, 1 week ago.

  • Author
    Posts
  • #4104

    Now perhaps it is time to speak on more “adult” topics, and the first of them is the concept of a layered architecture in software development.

    Layered architecture is one of the architectural paradigms in software development, where functional areas of the application are divided into groups.

    What does this mean?

    All functionality of an application in one way or another can be divided into groups depending on what task this functionality is performing, and how exactly the application is performing the task (it can be communication with the user, or performing data validation, or manipulating data retrieved from a database, or describing entities, or describing logic, etc.).

    The task of a layer defines its role and responsibilities.

    If we want to develop an application architecture correctly we need to define each layer so that it can be easily replaced by a similar one or reused in another application. This is achieved through the so-called decoupling (low cohesion). Low cohesion – is the result of proper use of the principles of object-oriented programming, such as abstraction, and polymorphism.

    To make it easier to understand the multi-layer architecture essense let’s imagine a pyramid, where each successive level is located on the top of the previous one.

    A special feature of the pyramid is called an inverted pyramid of reuse, where each layer located above has information about how to access the layer located directly beneath it. But never vice versa !!!

    And now we need to clarify what layers are located on the top of the pyramid and which are beneath them.

    Just for the demonstration let’s take a look at the classic 3-layer architecture(UIL – BLL – DAL), but even it can include some additional layers.

    At the very top of the pyramid there is a layer of the user interface (UIL – User Interface Layer). Which technology will be involved – is another question, and it actually depends on the type of application. It may contain Windows Forms, it could be WPF application Page class , it may be ASP.NET Web Pages and many others. The main objective of this layer is to provide ergonomic user interface in accordance with the functionality described in the specification. User interface should just look nice, be comfortable and intuitive. At the same time it needs to know how it interacts with the layer located at a lower level, as it passes the data back, and how it retrieves it to display to user.

    As for the logic of a layer below, UIL knows nothing about it. What algorithms are performed in those methods, which are called by pressing a button or changing the text in the input field, or selecting an item from the list, the UIL remains blissfully unaware.

    Below the UIL there may be, for example, a layer of services that we are not going to discuss in detail right now, we better do it in another article devoted to SOA (service-oriented architecture). This layer might not be being involved in a three-layer architecture. Anyway, let’s continue…

    The next layer below is a Business Logic Layer (BLL ). It can include classes describing the entities and the basic logic of the application (the main algorithms of the application, calculations, data processing, etc.). For example, if we are writing a network game “Tic – Tac-Toe”, this layer can define classes describing playfield, the move, sending and receiving data over the network etc.

    One layer below is the Data Access Layer (DAL). It is working with the data source (databases of different vendors: MSSQL, MySql, Oracle …), or XML files, or binary data, or text files, in short, all permanent sources of data. The classes of this layer are also describing the logic, and data manipulation but it is aimed to interaction with the data source and transmission of the results to the upper layer.

    There may be more and more layers, but what they are and in what order they are arranged in an application architecture pyramid – depends on the type of the application.

    The main thing to keep in your mind about layered architecture – the next set of rules:

    • each layer performes a specific task
    • the logic of different layers is not repeated and does not intersect
    • it is clearly defined how to access the layer below
    • it is clearly defined how to pass the information to the layer above
    • layers are low coupled
    • layers are arranged vertically, although there is a pass-through functionality, which can permeate the pyramid from the top down
    • layers may physically reside on the same machine , and can be on different machines, for example, in distributed applications.
    • different layers logic is encapsulated, so different layers do not need to make any assumptions about how the code is implemented in the other layers of the application.
    • the possibility of using other scenarios (due to the low coupling and clearly defined tasks).

    I hope I clearly explained the concept of the layered application, their main rules and what is the advantage of using this architecture. If you have questions – I am ready to aswer.

You must be logged in to reply to this topic.