Advertisment

Layering

author-image
CIOL Bureau
Updated On
New Update

Avijeet Dash and Satyabrata Dash





Introduction



Complex application need to be broken down into group of subtasks, where each group of subtasks is at a particular level of abstraction.



Layering is a common technique to break a complex system into many logical layers, which are at different levels of abstraction. Layering is based on the principle of ‘Abstraction’. Abstraction is a very basic requirement for dealing with complexity. Human mind can deal with complexity to a certain limit, beyond that it’s difficult to work with complex systems. It’s a common technique to break the system into different layers with varying levels abstraction to manage complexity. Each layer is a group of subtasks, which is pretty independent in it self. For example, lets consider a microprocessor chip. From the outset it’s the input and output ports that give it the microprocessor functionality. If we look slightly deep into it, we will see silicon wafers. If we look into the silicon we will see electrons and protons. To understand how microprocessor does addition if we try to understand electron movements, we will never get there. Thus it’s very critical to work at the right level of abstraction to design and orchestrate a complex system.





In 30 Seconds



Layering is "divide and conquer" the software complexities. Layer your application in such a way that different layers will have minimal inter-dependencies and it should follow the thumb rule that a layer should not depend on the layers above it.





Motivation





    Advertisment

  1. Abstraction


  2. The benefit of abstraction is each layer can be seen in isolation and can be understood and implemented without knowing much about the other layers.



  3. De-coupling


  4. Layers can be substituted with alternate implementations of the same basic services. So each layer should have a clearly defined interface



  5. Ease of development


  6. As the dependency between layers is low, parallel development of these layers makes development faster.



  7. Standardization
  8. Each layer can implement a standard in itself.

    Why Layering?





    Typically enterprise applications have three parts to it presentation, domain logic and data source. The earlier client-server systems used to have a two layer system where the data store used to keep data, data access logic and domain logic in the form of stored procedures and GUI components used to talk to database for the display of data. This had the problem of tight coupling of code with data. Which made incorporating change difficult and duplicate codes in presentation and domain logic. With the coming up of Internet, applications got structured to multiple layers. The latest J2EE Patterns publication suggest a 5 layer architecture

    Advertisment









































    Core J2EE



    Layers



    Client



    Presentation that runs on client (html browser or fat client like java swing etc.)



    Presentation



    Presentation part that runs on server (JSP, Servlets)



    Business



    Domain Logic



    Integration



    Data source (RDBMS, ODBMS)



    Resource



    The external resource (Lagacy systems like ERP, Mainframes etc)



     



    Structure







    From the structure two things to note are





    1. Each layer provides the services to the next layer above it


    2. Each layer delegates the sub tasks to the lower layer

    Thus though the layers stand for themselves they collaborate with the layer above and below them using an agreed upon interface.

    Complexities Simplified





      Advertisment

    1. Tiers and layers



    2. Fowler clearly distinguishes between tiers and layers. For most people, tier is a physical separation where as layer is logical division. So for example Client-server systems are often described as two-tier systems, and the separation is physical: the client is a desktop and the server is server. But you can have presentation, business and data source layers run on the same machine.



    3. How many layers?


    4. One of the challenges is to define the abstraction criterion for grouping tasks into layers. Determining the number of abstraction levels depends on the abstraction criterion. This has the trade-offs when deciding whether to split particular aspects into two layers or combine them into one.

    5. Design an error-handling strategy


    6. Error handling can be rather expensive for layered architectures with respect to processing time and programming effort. The best practice is to handle errors as much as in the same layer as possible, and only propagate generic errors to upper layers.

    7. Performance




    8. Advertisment

      The performance of a layered application might be worse than a monolithic application, especially when different layers are distributed. So layers must follow the standard patterns like Session Façade, Data Transfer object patterns to communicate between two layers.





      Related patterns



      1. M-V-C pattern


      2. Session Façade


      3. Data Transfer object


      4. Application Controller
      5. Conclusion



        Layering is an architectural decision, which has to be made at the beginning of project. The three most common layers in an enterprise application are Presentation, Domain and Data source, although there can be more fine-grained layers depending on complexity of a system.



        Resources:



        1. Patterns of Software Enterprise Architecture by Martin Fowler,David Rice , Matthew Foemmel , Edward Hieatt , Robert Mee , Randy Stafford


        2. Pattern-Oriented Software Architecture A System of Patterns by F. Buschmann, R. Meunier, H. Rohnert, P.Sommerlad, M. Stal
        3. tech-news