How do I create a domain model related to managing confidential documents?

I am working on a desktop application that specifically deals with the application of read and write permissions for confidential documents (MS Word).

Multiple permissions can be defined for a document. For example:

  • user X can read document D1 between start_date and end_date
  • user Y can read and edit document D1 at any time

In addition, the permission set for the document must be available for display in the user interface.

In addition, the document can be signed (with a certificate) by the current user of the application (the author of the documents).

Lately (after you have objects with less behavior and some line of business / applications) I came up with this:

interface IConfidentialDocument {
    void AddPermission(Permissions permission);
    BunchOfPermissions Permissions { get; } // all defined permissions
    void Sign(User currentUser);
    ... other operations (like ShareToUsers, SendViaEmail)
    string Path { get; }
}

class Permission {
    User User { get; private set; }
    PermissionType Type { get; private set; } // Read, Write, Full etc.
    ... other members (for time bounds etc.)
}

      

The problem is that IConfidentialDocument has to be implemented using the Word Interop library . I couldn't discern a good way to wrap the Word Interop functionality and hide my corrupt design in a simpler model as shown above.

I was thinking about embedding IConfidentialDocument as WordDocument, which delegates this work to Microsoft.Office.Interop.Word.Document. The latter will be passed in the constructor of the WordDocument. This will create ConfidentialDocumentFactory.Create (string). The specific factory will depend on Microsoft.Office.Interop.Word.Application etc.

  • Is there a DDD way to work with such a domain?
  • (How) should I define an anti-corruption layer over / against Word Interop?
  • Should I make the domain anemic and define services like DocumentsSigningService, PermissionsApplyingService? - actually, this is what I have now - it works, but ...
  • Is it possible to use double dispatch?
    • document.SignVia (signingService)
    • document.ApplyPermissionsVia (permissionsService, bunchOfPermissions)

Business is actually a little more complicated. It also includes sending documents to their authorized users (via email), etc. What I've done so far relies on a set of business services and application services to do most of the logic - the ConfidentialDocument thus has nothing to do with behavior. But as I said, I am looking for the best design.

Any idea is appreciated :)

Thank!

Some links (not enough reputation to add links):

  • How not to inject services in essence (thinkbeforecoding)
  • Best Domain Event Model (lostechies)
+3


source to share


1 answer


The question is too big and I don't understand why WordDocument: IConfidentialDocument is bad. It can be allocated in a separate module and is considered an adapter.

Okay, I'll try to express my thoughts.

As far as DDD is concerned, you should make your own model as large as possible.

MS Word uses its own model containing concepts such as User, Permission and Document. Therefore, it is necessary to make model translations between your entities and data presented by MS. There are several points of interest to consider.

Model translation

  • What is the relationship between your model and the MS Word model? For example, if someone changes MS Word permissions directly (bypassing your application), can your application always respond correctly to that change? And vice versa. So, first I was defining the relationships between the models and would make some constraints.

  • Does your application support any other types of documents / providers (OpenOffice)? You can analyze details based on specific document providers and separate them from your own model.

Document Model

  • Should you always load the "real document" into memory when you create the application document object? I think not. Hence the proxy is fine.

  • Are there any basic fields or document states that are common to all documents regardless of the type of physical document? If yes, then the base abstract class "PhysicalDocumentState" as a field of the document object will match this good one.



I suggest something like this:

Model

I use words like Service, State, Facade to refer to the corresponding templates.

You may not need to implement WordDocument, WordPermission, but:

  • this can be helpful as it simplifies the WordFacadeService
  • it will completely isolate WordState from MSOfficeInterop and focus on domain activities first.
  • when the document type is created, WordState initializes the WordFacadeService and hence it can implement different document initialization logic (like lazy loading).

The only problem now is defining a simple and transparent interface for the WordFacadeService and separating the responsibilities of constraint constraints between WordState and WordFacadeService.

Finally, I have no idea why you should use the Anemic Domain Model in the described case.

I would be glad if it helps.

+2


source







All Articles