{"id":47,"date":"2018-03-16T09:54:48","date_gmt":"2018-03-16T16:54:48","guid":{"rendered":"https:\/\/blog.kineteque.com\/?p=47"},"modified":"2018-03-16T09:54:48","modified_gmt":"2018-03-16T16:54:48","slug":"the-layered-architecture-pattern","status":"publish","type":"post","link":"https:\/\/blog.kineteque.com\/?p=47","title":{"rendered":"The Layered Architecture Pattern"},"content":{"rendered":"<p>Len Bass, Paul Clements, and Rick Kazman best explain the Layered Architecture as, &#8220;The Layered Architecture Pattern\u00a0defines\u00a0layers as a grouping of modules or services\u00a0and a unidirectional\u00a0<em>allowed-to-use<\/em>\u00a0relation among layers. Layers must have a strict-ordering relation, in which a layer can only use public interfaces of a layer below,&#8221; in the book Software Architecture in Practice<span id=\"RNSTf5oUUsUOCT7F1bSVU\" class=\"abt-citation noselect mceNonEditable\" data-reflist=\"[&quot;3844383451&quot;]\" data-footnote=\"undefined\"><sup>1<\/sup><\/span>.<\/p>\n<p>The benefit of the layered-architecture is that it allows for a separation of concerns, allows for a division of labor, and it is typically easy to refactor a top layer.<\/p>\n<p>Its drawback is that there is a performance cost\u00a0for each layer, and it can be very expensive to refactor lower layers.<\/p>\n<p><!--more--><\/p>\n<h2>The Layered Architecture applied as reference architecture for a RESTful Application<\/h2>\n<p><a href=\"https:\/\/blog.kineteque.com\/wp-content\/uploads\/2018\/03\/Layered-Architecture.svg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-60\" src=\"https:\/\/blog.kineteque.com\/wp-content\/uploads\/2018\/03\/Layered-Architecture.svg\" alt=\"\" \/><\/a><\/p>\n<h3>The Presentation Tier<\/h3>\n<p class=\"p1\">A well-designed architecture could easily switch Presentation Layer implementations with different technologies. Perhaps this could be a Swing Application, Command Line Application, or MVC framework with server side templating. This particular example documents a Layered REST application.<\/p>\n<h4 class=\"p1\">Serialization Segment<\/h4>\n<p>The Serialization segment provides a set of classes per each serializable request and response types (i.e.\u00a0Plain Ordinary Java Object\u00a0that <a href=\"https:\/\/github.com\/FasterXML\/jackson\">Jackson<\/a> could easily convert to and from JSON).<\/p>\n<h4>Transformer Segment<\/h4>\n<p>The Transformer segment will convert\u00a0serializable request and response\u00a0classes into Domain \/ Model classes.<\/p>\n<h4>REST Endpoint Declarations Segment<\/h4>\n<p>The REST Endpoint Declarations will each declare a PATH, an Accept type, a Content-Type, a serializable request class, and a serializable response class.<\/p>\n<p>It will receive the Serializable Request, transform it into the appropriate Domain \/ Model class, and call the appropriate Business Logic Service class, transform the result into Serializable Response, and finally respond.<\/p>\n<h3 class=\"p1\">Business Logic Services Layer<\/h3>\n<p class=\"p1\">The Business Logic Services Layer receives a domain object from the Presentation Layer, and provides business functionality. It will use the Client Interface to communicate to other components in a system or the Persistence Layer to persist data.<\/p>\n<h3 class=\"p1\">Client Interface Layer or Persistence Layer<\/h3>\n<p class=\"p1\">The Client Interface Layer is responsible for sending or receiving data from other systems.<span class=\"Apple-converted-space\">\u00a0 <\/span>This might also be a Persistence Layer that merely persist data into a data-store. For example, this could be a set of Data-access Objects that use JPA.<\/p>\n<h3 class=\"p1\">Domain \/ Model Layer<\/h3>\n<p class=\"p1\">The Domain \/ Model layer should attempt to provide an object-oriented model of your business. It is good to implement business logic here, but keep in mind that business logic computations often require external persistence, and it is anti-pattern to couple persistence technologies with a domain object. These absolutely should be Plain Ordinary Java objects, and depending your threading model, perhaps immutable as well.<\/p>\n<div id=\"abt-bibliography\" class=\"abt-bibliography noselect mceNonEditable\" data-reflist=\"[&quot;3844383451&quot;]\">\n<div id=\"abt-bibliography__container\" class=\"abt-bibliography__container\">\n<div id=\"3844383451\">\n<div class=\"csl-entry flush\">\n<div class=\"csl-left-margin\">1.<\/div>\n<div class=\"csl-right-inline\">Bass L, Clements P, Kazman R. <i>Software Architecture in Practice<\/i>. Addison-Wesley Professional; 2012.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Len Bass, Paul Clements, and Rick Kazman best explain the Layered Architecture as, &#8220;The Layered Architecture Pattern\u00a0defines\u00a0layers as a grouping of modules or services\u00a0and a unidirectional\u00a0allowed-to-use\u00a0relation among layers. Layers must have a strict-ordering relation, in which a layer can only use public interfaces of a layer below,&#8221; in the book Software Architecture in Practice1. The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-architecture-patterns"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":0,"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kineteque.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}