Separation of Presentation and Domain
Overview
Presentation and Domain Separation is a design principle that separates user interface code from other code.
Separation of Layers
Separating the domain layer and presentation layer is particularly important.
- Presentation Layer
This layer interacts with the user (implementing commands and event handlers, providing a user interface, displaying and outputting results, etc.) and does not include domain logic. - Domain Layer
This layer realizes operations on concepts such as design information, so-called domain logic, without being aware of the state or display of the user interface. There are models that represent concepts and states related to the domain, and services that realize operations on multiple models.
This completely separates the software logic from the UI, making unit testing easier. Since the behavior of the application is in the domain layer, it is highly reusable, and in the future it will be possible to run extension functions in CI or turn them into command line applications.
Project separation
It is very important to maintain the principle of separation of the presentation layer and the domain layer in the architecture, but to prevent inadvertent violation of responsibilities, it is strongly recommended to separate the presentation layer and the domain layer into separate projects.
- Presentation -
MyExtension.csproj
References NextDesign.Desktop and UI libraries.
The recommended target framework is .NET 8.0. - Domain -
MyExtension.Core.csproj
References only NextDesign.Core and non-UI libraries.
The recommended target framework is .NET Standard 2.0, but if the referenced library has .NET Standard 2.1, it will be .NET Standard 2.1.
By separating them in this way, you can ensure that there are no references from the domain layer to the presentation layer. If you do not separate the projects, you may accidentally reference something and before you know it, you may find that a dependency has been created, so we recommend separating these two projects.
By separating projects not only by layer but also by function, you can eliminate dependencies between functions.
Control by accessibility
Even if you separate the projects, if you refer to various classes from the outside, you will be affected by changes to the internal design. Therefore, only expose classes and methods that are the entrance from the outside, and make other classes and methods private.
Keep what is exposed to the outside to a minimum, so that changes to the logic or expansion of functions do not affect the users.
For details, see Implementation Concealment by Accessibility.