如何避免SRP混乱? [英] How to avoid SRP chaos?

查看:47
本文介绍了如何避免SRP混乱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过应用SRP原理,您必然会拥有很多类.如果这对于小型项目而言行之有效,那么您如何处理和组织大型项目中的课程数量呢?

By applying the SRP principle you are bound to have a lot of classes. If this works fine for a small project how can you handle and organize the amount of classes on a large project ?

  • 您如何组织文件夹结构?
  • 您如何记住自己的建筑?
  • 您如何知道其他人是否在其他课程中没有构建相同的功能?

推荐答案

这适用于所有类型的库.不只是SRP.

This applies across all types of libraries. Not just SRP.

类/函数的组织可能令人头疼,但是实际上您只需要记住几件事.

Organization of classes/functions can be a headache, but really there are only a few things you need to bear in mind.

  1. 计划.
  2. 定义并保持正确的命名 文件,类的约定, 文件夹,方法/功能和 变量.
  3. 将类分为名称空间 或至少进入子文件夹 系统的主要肌肉群.
  4. 文档:内部(好评, 文件标题和公共方法 列表)和外部(Wiki, 自述文件,excel等)
  1. Plan.
  2. Define and keep a proper naming convention for files, classes, folders, methods/functions and variables.
  3. Break your classes into name spaces or at least into sub-folders by the major muscle groups of the system.
  4. Document: internally (good comments, file headings, and public method lists) and externally (wiki, readmes, excel, something)

按2表示:/library/muscleGroup/useType_nameOfClass.php用于文件/文件夹,其中useType类似于工厂",抽象",数据/dto"或您正在使用的任何模式.然后,在每个文件中,类应与nameOfClass完全相同,并且每个方法的名称应严格遵循模式. [Action][on what][with what conditions]并保留动作列表和关于"内容,并坚持执行.

By 2 I mean: /library/muscleGroup/useType_nameOfClass.php for files/folders where useType is something like "factory" "abstract" "data / dto" or whatever patterns you are using. Then, in each file the class should be the exact same thing as nameOfClass and each method name should strictly follow a pattern. [Action][on what][with what conditions] and keep a list of actions and 'on whats' and stick to them RELIGIOUSLY.

这样做,您就无法复制功能,因为您可以轻松找到所需内容的正确类和方法.由于它们具有类似Get_User_ByIdGet_Transactions_ByNewestCombine_Ingredients_FromRecipes的逻辑名称.

Do that, and you can't duplicate functionality, since you can easily find the right classes and methods for the things you want. Since they have logical names like Get_User_ById and Get_Transactions_ByNewest or Combine_Ingredients_FromRecipes.

最后一个可能在其上方有一条评论,例如:

That last one might have a comment above it like:

// Combines many recipes into one ingredient list
//   $recipes = an array of recipe objects
//   returns an array of ingredient objects with their correct quantities


示例操作列表:(应该非常通用,适用于任何应用程序


List of sample Actions: (should be pretty generic and apply to any application)

  • 获取
  • 设置
  • 删除
  • 移动
  • 合并
  • 组合

关于什么"示例列表:(应特定于应用程序)

List of sample "On What"s: (should be application specific)

  • 用户
  • 成分
  • 食谱
  • 测量
  • 权限
  • 品牌
  • 广告

这篇关于如何避免SRP混乱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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