douzhang5984 2013-03-30 11:19 采纳率: 100%
浏览 47

PHP中的域驱动设计架构

In a PHP DDD application with a folder structure like this:

app/
    views/
    controllers/
    domain/
        models/ ( orm generated )           
        services/
        factories/  

what would the following classes represent(from a DDD terminology point of view) and what would be the recommanded location for them.

Dictionary ( basic functionality: checks if a word is valid ) HtmlValidator ( basic functionality: checks if a string is a valid html ) UserCollection ( basic functionality: operations on a collection of users )
  • 写回答

2条回答 默认 最新

  • duanaoreng9355 2013-03-30 12:36
    关注

    This doesn't look like a DDD application.

    In particular, ORM generated models are not domain models. This is a good thing, if your application core value is in data and you just need to handle CRUD operations.

    In a DDD application models comes from the language of the domain expert, that is a person that know that business that your application target as it's his own job but does not know anything about tech.

    If your domain expert talks about Dictionaries and UserCollection (quite strange, btw) such classes are actually models. HtmlValidator, almost by definition, is not a business term.

    I suggest you to avoid using DDD tecniques if the value of your application comes from technological components. Use DDD only for applications that handle very complex business rules.

    edit
    Most of times domain models worth (at laest) a separate module. In PHP I would suggest you to bundle it in (at least) a separate package. However using the MVC pattern does not imply to use DDD: you can use MVC for a data driven application, and that's fine. In such case I would put in models only ORM generated classes. In such a scenario I would put all that classes in a controllers/lib folder.

    评论

报告相同问题?