{"action":"created","issue":{"url":"https://api.github.com/repos/tomoya92/pybbs/issues/26","repository_url":"https://api.github.com/repos/tomoya92/pybbs","labels_url":"https://api.github.com/repos/tomoya92/pybbs/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/tomoya92/pybbs/issues/26/comments","events_url":"https://api.github.com/repos/tomoya92/pybbs/issues/26/events","html_url":"https://github.com/tomoya92/pybbs/issues/26","id":185639985,"number":26,"title":"包结构划分方式的讨论","user":{"login":"TakWolf","id":6064962,"avatar_url":"https://avatars.githubusercontent.com/u/6064962?v=3","gravatar_id":"","url":"https://api.github.com/users/TakWolf","html_url":"https://github.com/TakWolf","followers_url":"https://api.github.com/users/TakWolf/followers","following_url":"https://api.github.com/users/TakWolf/following{/other_user}","gists_url":"https://api.github.com/users/TakWolf/gists{/gist_id}","starred_url":"https://api.github.com/users/TakWolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TakWolf/subscriptions","organizations_url":"https://api.github.com/users/TakWolf/orgs","repos_url":"https://api.github.com/users/TakWolf/repos","events_url":"https://api.github.com/users/TakWolf/events{/privacy}","received_events_url":"https://api.github.com/users/TakWolf/received_events","type":"User","site_admin":false},"labels":[{"id":198531260,"url":"https://api.github.com/repos/tomoya92/pybbs/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-27T11:16:14Z","updated_at":"2016-12-29T10:23:47Z","closed_at":null,"body":"只是一个讨论，因为这个问题本身存在争议。\n\n现有的包结构是安装功能模块划分的：\n\n```\nmodule\n  collect\n  index\n  notification\n  reply\n  topic \n  user\n```\n\n每个模块通常包含四个包：\n\n```\ncontroller\ndao\nentity\nservice\n```\n\n目前这么分包存在的问题：\n1.包结构特别多，但是很多包其实只有一个类，比如：module.user.service.UserService.java 只有这一个类\n2.命名冗余，例如 module.user.service.UserService.java ，他本身就存在于 Module.user 包，那么 UserService 前面的User是不是冗余的？\n3.依赖结构应该是内聚的，例如 UserService 应该是一个用户相关的业务类，但是其实跟用户相关的模块，例如 topic，notification都会用到，这些跟user模块是平行关系，但是却是互相依赖。所以UserService是不是应该是高于module的结构？\n4.有一些类没地方放，例如 BaseController，BaseEntity被放到了common包里，Result其实应该属于entity（尽管他不是一个domain），现在只能放到 util 里面的。\n5.无法纵向分层。举个例子，很多网站是这样部署的：\nbbs.tomoya.com -> 网站端\napi.tomoya.com -> Api端\n这两个跑在独立的端口，是两套程序，这样的结构很常见。\n假如我现在有了这样的需求，想要对pybbs做改造，可能的改造思路是：\n把现有的项目拆分成三个子项目，分别是：\ncore  -> 包含 entity，dao，service\nweb -> 依赖于core，包含 webController，webService，是个可执行程序\napi -> 依赖于core，包含 ApiController, apiService，是个可执行程序\n未来可能构造一个聊天室 chat.tomoya.com -> 依赖于 core 核心业务区扩展就行了\n现有的分包模式很难做这样的改造，因为无法提取core\n\n----------- 分割 --------------\n\n结构应该是自顶向下的：\nController\n依赖于\nService\n依赖于\nDomain\n\n对于底部的是依赖关系，而对于顶部的则完全不可知\n\n----------- 分割 --------------\n\n按照上面的理由，更合理的一种方式可能是安层分或者按照类功能分：\n\n```\nconfig\ncontroller\n   web\n      IndexController.java\n   api\n      UserApiController.java\nservice\ndomain\n   entity\n   dao\nutil\n```\n\n我最早也是按照module分包，经过实践目前倾向于按照层分包。\n当然这个问题本身也存在争议，社区也有广泛的讨论。\n\n这个issues只是一个讨论，不一定是一个建议。目的是希望可以找到一个最佳实践。\n"},"comment":{"url":"https://api.github.com/repos/tomoya92/pybbs/issues/comments/269609998","html_url":"https://github.com/tomoya92/pybbs/issues/26#issuecomment-269609998","issue_url":"https://api.github.com/repos/tomoya92/pybbs/issues/26","id":269609998,"user":{"login":"x-pengg","id":10755158,"avatar_url":"https://avatars.githubusercontent.com/u/10755158?v=3","gravatar_id":"","url":"https://api.github.com/users/x-pengg","html_url":"https://github.com/x-pengg","followers_url":"https://api.github.com/users/x-pengg/followers","following_url":"https://api.github.com/users/x-pengg/following{/other_user}","gists_url":"https://api.github.com/users/x-pengg/gists{/gist_id}","starred_url":"https://api.github.com/users/x-pengg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/x-pengg/subscriptions","organizations_url":"https://api.github.com/users/x-pengg/orgs","repos_url":"https://api.github.com/users/x-pengg/repos","events_url":"https://api.github.com/users/x-pengg/events{/privacy}","received_events_url":"https://api.github.com/users/x-pengg/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T10:23:47Z","updated_at":"2016-12-29T10:23:47Z","body":"其实我觉得可以改为 Maven 的 Module 结构"}}
{"actor":{"display_login":"x-pengg"}}