简体   繁体   中英

Layered Architecture: Application and Infra Layer

I'm starting to learn about Software Architecture and I've seen some layered architecture implementations that got me confused.

In general terms, those solutions have the following layers:

  • Presentation Layer;
  • Application/Service Layer;
  • Domain Layer;
  • Infra/Data Layer;

I'm not certain about:

  1. It's not totally clear to me how each one of those layers work, what are their concerns;
  2. It's not clear to me which layers communicate with the Data Layer. Is it the Application Layer? Some people say that the Application Layer shouldn't have any reference or knowledge about the data layer;

If someone could answer me those questions or recommend me some resources to learn more about it, I would appreciate.

Thanks and have a nice day! :)

  • Presentation Layer: As it's name suggests this layer's concern is whatever the user sees or interacts with. It contains UI logic, graphics, forms, images, ...

  • Domain Layer: This is where your business logic is handled. If you are writing a weblog this layer contains objects and entities like Posts, Users, Comments, etc. If you are writing a financial system they would be Ledger, Accounts, Money, etc. The most valuable codes of your system rely here, because they satisfy user concerns.

  • Infrastructure Layer: In the classic sense every layer only accesses the underlying layer, but sometimes this layer covers concerns of multiple layers. So I doubt if you can call this one a layer in the classic sense. It contains application wide abstractions and base classes, and sometimes cross cutting concerns, etc.

  • Service Layer: " A common approach in handling domain logic is to split the domain layer in two. A Service Layer is placed over an underlying Domain Model ", Martin Fowler, PoEAA. As Martin Fowler says in his book (I recommend you to read the book) this is a layer on top of your domain to make the usage of your domain easier. So that it's clients don't have to know anything about domain complexities. It contains Facades. And also a good place for handling some concerns like security, transaction management, and etc.

  • Data Layer: This layer manages the storage logic. It could be a simple file or some big relational database. In simple projects where there is no or little business logic Data layer plays the "Domain Layer" role or vice versa. Actually it's not important. What is important is that there could be some impedance mismatch between the domain model and the data structure. The main concern of Data Layer is to handle this difficulty for other parts of the application (specially Domain Layer).

Which layer communicates with data? Most of all the Domain Layer. But it's not always true. Suppose you want to save some user preferences of UI in the database. So the Presentation layer can also communicate with the Data Layer. Actually any layer can communicate with the Data. What is important is that you should use patterns and best practices (like IOC) to make the best out of your project needs.

Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM