Skip to main content

Presentation and Domain Separation

Overview

Presentation and Domain Separation (PDomain Separation) is a design principle that separates user interface code from other code.

Layer Separation

Separating the domain layer and the presentation layer is particularly important.

  • Presentation Layer
    This layer handles user interaction (implementing commands and event handlers, providing the user interface, displaying and outputting results, etc.) and does not include domain logic.
  • Domain Layer
    This layer implements operations on concepts such as design information, so-called domain logic, without being aware of the state or display of the user interface. It includes models that represent concepts and states related to the domain, and services that enable operations on multiple models.

This completely separates the software logic from the UI, making unit testing easier.

Since the application's behavior resides in the domain layer, reusability is increased, and it becomes possible to run extension functions in CI or create command-line applications in the future.

Project Separation

Maintaining the principle of separating the presentation layer and the domain layer architecturally is crucial, but to prevent unintentional breaches of responsibility, 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 target framework is recommended to be .NET 10.0.

  • Domain - MyExtension.Core.csproj
    References only NextDesign.Core and non-UI libraries.
    The target framework is recommended to be .NET Standard 2.0, but if any referenced libraries use .NET Standard 2.1, then .NET Standard 2.1 will be used.

This separation ensures that there are no references from the domain layer to the presentation layer.

If projects aren't separated, you might accidentally reference them and end up with dependencies, so it's recommended to separate these two types of projects.

Separating projects not only by layer but also by function can eliminate dependencies between functions.

Control through Accessibility

Even with project separation, referencing various classes from the outside can still affect changes in the internal design. Therefore, only expose the classes and methods that serve as entry points from the outside, and keep all other classes and methods private.

Keep what's exposed externally to a minimum, and ensure that logic changes and feature extensions don't affect the user.
For details, see Hidden Implementations with Accessibility.