官术网_书友最值得收藏!

A layered architecture versus a non-layered architecture

Not every application needs to be built in a heavily layered manner. Not every application needs to be overly extensible. Some applications need to be built quickly and simply for the sole purpose of getting them out the door. However, be careful not to build something simple when something flexible should have been built in its place. While you can easily grow an application that was built with growth in mind, extending an application that was built without growth in mind can be difficult, if not near impossible.

Knowing that our application is going to be a large undertaking that should last for some time, we need to design something that can be easily extended as the need arises. For that we will try to design this application with extensibility in mind. The easiest way to do that is to follow the general rule of maintaining "separation of concerns".

Note

Separation of concerns (SoC) is the process of breaking down your application into specific units of functionality in such a way that each unit only addresses the need of one concern with as little overlap as possible with other units in terms of functionality. Look here for more information regarding this topic: http://en.wikipedia.org/wiki/Separation_of_concerns

Layers

The easiest way to maintain SoC is to first break major areas of your application into layers. In most applications, this might be broken down into the presentation, business logic, and data access layers.

  • Presentation: This layer would normally hold anything pertaining to the user interface of your application—the buttons, links, and other controls that a user would click on and interact with while using your application.
  • Business Logic: This is where the rules of your application would live. This could be as simple as formatting the currency of a price in your product catalog to something more complex such as enforcing rules regarding data input.
  • Data Access: The data access layer is responsible for connecting to a data source and interacting with the data that is stored in that location. This could be a database, some XML files, text files, or even a web service.

    Note

    There is a common argument amongst enterprise developers regarding the use of layers. It says something along the lines of "the more the objects in use, the more the resources in use". This is of course a true statement. However, the use of more resources in this case does come with a benefit in the form of greater flexibility in your application. Layers promote SoC as well, which directly benefits the developer as the physical code is easier to understand and work with.

I used to think that just these three layers were good enough and used them in several applications. However, I always found myself wanting more control in my application. Recently I worked on a project that expanded on these very common layers (into more layers of course) with the use of Domain-driven Design.

主站蜘蛛池模板: 马龙县| 台北市| 临高县| 贵南县| 新兴县| 宁化县| 梅河口市| 肃北| 蒲江县| 壶关县| 延川县| 南丰县| 萨嘎县| 繁昌县| 英吉沙县| 余姚市| 加查县| 鄂伦春自治旗| 尚义县| 铜鼓县| 郧西县| 白朗县| 西昌市| 岐山县| 贵州省| 会宁县| 建湖县| 宁国市| 历史| 扬中市| 中阳县| 海原县| 收藏| 六枝特区| 土默特左旗| 明光市| 绥棱县| 云和县| 临洮县| 巧家县| 高青县|