组织基于DDD的Web应用程序的目录结构? [英] Organizing the directory structure of my DDD-based web application?

查看:597
本文介绍了组织基于DDD的Web应用程序的目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始放弃使用普通的MVC创建Web应用程序的方式,并开始研究域驱动设计-DDD。

I have started to look away from the normal MVC way of creating my web applications and have had a look at Domain Driven Design - DDD.

从<$仅c $ c> Models ,我现在有 Collections 实体 DataMappers &我的应用程序中的存储库。完全可以确定的分离和模块化,但是现在我的目录结构不过是一团糟!

From having Models alone, I now have Collections, Entities, DataMappers & Repositories in my application to work with. Full-fledged separation and modularity for sure, but now my directory structure is nothing but a complete mess!

由于我过去从未使用过DDD应用程序,我对如何组织文件结构一无所知。

As I have never worked with a DDD-application in the past, I have little idea on how to organize my file structure.

下面是否将是合适的目录结构?

注意:我使用的是PHP5,但我认为这个问题与语言无关。

Would below be an appropriate directory structure?
Note: I am using PHP5, but I reckon this question to be close to language-agnostic.

/application
    /common
        /libraries
        /helpers
    /temp
        /cache
    /domain
        /collections
        /entities
        /datamappers
        /repositories
    /ui
        /controllers
        /view


推荐答案

我认为这很有意义,但是,这会将您的模块分成它们所在的图层,而不是它们做什么。例如,在这种结构中,如果您需要身份验证和打印模块,则可能会有以下内容:

I would think that makes sense, but, that is going to separate your modules into what layer they are at, rather then what they do. For example, in this structure, if you wanted an Authentication and printing modules, you would have probably something like this:

    /common
        /helpers
             /Authentication
                 /AuthenticationService.php
             /Printing
                 /PrintingService.php
    /domain
        /entities
             /Authentication
                 /Identity.php
             /Printing
                 /Printer.php
        /datamappers
             /Authentication
                 /IdentityDataMap.php
             /Printing
                 /PrinterDataMap.php

在这样的系统中工作,我可以说一个事情变得非常困难,以防止模块之间的边界相互啮合,这仅仅是因为人类正在各层中工作,并且将各层视为全部。从组织的角度来看,我真的不喜欢必须打开三个根目录才能使用特定模块。我们将项目组织到目录中,以使我们更易于处理,而不是编译器。

Having worked in a system like this, I can say for one thing, it gets very hard to keep the boundaries between modules from inter-meshing, just because humans are working in the layers, and thinking of the layers as 'all together'. Just from an organizational standpoint, I don't really like having to have three root level directories open to work with a particular module. We organize projects into directories to make it easier for us to deal with, not the compiler.

如果我再做一次,我会分隔 some 一层一层地讲UI代码,而另一层上讲业务代码,然后在下一层按模块。我想更多的是混合动力,但也许更好。

If I was doing it again, I would separate some things by layer, say UI code, on one level, and business code on another, but then by module under that. More of a hybrid I suppose, but perhaps better for it.

    /domain
        /Printing
            /entities
            /datamappers
            /repositories
        /Auth
            /entities
            /datamappers
            /repositories
    /ui
        /controllers
        /view

这篇关于组织基于DDD的Web应用程序的目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆