This is a good way to organize the classes from the service layer?
Currently I have the foll开发者_Python百科owing structure:
Model/
Entities/
Repositories/
Proxies/
Services/
User/
Manager.php
Relations/
Friendship.php
Group/
Manager.php
Administration.php
Posts/
Manager.php
...
Since I'm using Doctrine, I have chosen this structure because each folder corresponds to one entity. Are there any problems in organizing this way?
I would like to know your opinion on how to avoid changes to the folders' structure in the future caused by bad organization now. Is there a better way to organize the classes from the service layer? What can you recommend? Thanks.
It looks like a perfect valid structures, however, I may have two recommendations :
I usually put my proxies outside of my library folder, because first, it is a special class which doesn't follow the
PSR-0
recommendation, and second, you may need to remove those class when doing database update, for those reasons, I put them in/var/tmp/proxies
The service layer structure looks ok, but be sure to apply to your logic and not to your entities, I mean, a UserService is perfectly valid to gather all logic behind a user, but may also be used with some other entities because of their relationship. Conclusion "One Entity !== One Service"
I also avoid Plural form, that's a bit personnal point, but it is a bit similar to the naming convention used in Database System, a table represent a entity and therefore shouldn't accept plural forms. By the way, most of the framework (ie. Zf/Symfony2/Doctrine2) use singular.
Last but least, whatever structure you choose now, be consistent, we'll never tell it enough, I sometimes take projects back from other people, and even I don't understand why or how they did it like this, I try to follow their conventions, when working on a project with a team, it is a requirement.
If you decide one day to refactor your structure, take a day or two, and do it every where, or don't.
精彩评论