简体   繁体   English

类计数指标的含义

[英]Meaning of Class count metrics

We are working on a bigger project with Ruby on Rails. 我们正在与Ruby on Rails一起进行更大的项目。 As you might know, Rails works with MVC pattern and typically enforces the following class types for Domain objects: 如您所知,Rails使用MVC模式,通常为Domain对象强制执行以下类类型:

  • Controllers (+ Helpers) 控制器(+助手)
  • Models 楷模
  • Views (eg erb) 视图(例如erb)
  • Serializers 串行器
  • Mailers 寄件人

We experienced - like many other teams - that this is not feasible for bigger, long-running projects. 与许多其他团队一样,我们经验到,这对于大型,长期运行的项目是不可行的。

So in our current project, we added some layers, so we typically have 因此,在当前项目中,我们添加了一些层,因此通常

  • Controllers (+ Helpers) 控制器(+助手)
  • Policies (access control per controller) 策略(每个控制器的访问控制)
  • Presenters (aka ViewModel) 演示者(又名ViewModel)
  • Forms (containing all attributes available in an HTML form) 表单(包含HTML表单中所有可用的属性)
  • Views 查看
  • Models 楷模
  • Queries (static ActiveRecord queries) 查询(静态ActiveRecord查询)
  • Serializers 串行器
  • Mailers 寄件人
  • Services (Domain Service which extracts business code from controller) 服务(域服务,从控制器中提取业务代码)

It is much more testable, maintainable and understandable. 它更具可测试性,可维护性和可理解性。 However, our boss disagrees with "These are too many classes". 但是,我们的老板不同意“这些课程太多”。

As he is typically a proficient architect (doing consulting), I don't want to simply reject this response. 由于他通常是一位熟练的架构师(从事咨询工作),所以我不想简单地拒绝这种回答。 However, his time as active Java developer are gone and he often explains such sentences with his improved "gut feeling". 但是,他不再是活跃的Java开发人员,他常常以改善的“直觉”来解释这样的句子。

Of course, there are metrics that count classes - but is there a general approach to classify something like 'Classes per Domain object' or 'Class per Business case', which can be taken for an argument? 当然,有一些度量值可以统计类-但是是否有一种通用方法可以对诸如“每个域对象的类”或“每个业务案例的类”之类的东西进行分类呢?

I have never heard of a rule or best practice which limits a number of classes per project, domain or whatever. 我从未听说过一个规则或最佳实践,该规则或最佳实践限制了每个项目,领域或任何其他项目的类数。 One should create as many classes as he REALLY needs. 一个人应该创建他真正需要的尽可能多的类。 The key word here is "REALLY" because quite often developers over complicate things and create unnecessary classes, layers or even tiers. 这里的关键词是“ REALLY”,因为开发人员经常使事情复杂化并创建不必要的类,层甚至层。 Without the details about your project I suggest you do the following: 如果没有有关您的项目的详细信息,我建议您执行以下操作:

  1. Ask your boss to elaborate on the "Too many classes" phrase. 请您的老板详细说明“课程过多”一词。 Ask for his concerns. 询问他的担忧。 If he is a good architect and a team member he understands his responsibility of coaching people. 如果他是一位优秀的建筑师和团队成员,那么他会理解他指导人的责任。
  2. Make sure you clearly explained to him why you needed those classes. 确保您清楚地向他解释了为什么需要这些课程。 Provide examples. 提供示例。
  3. If your boss is stubborn, his best days as a developer are gone and he just wants to show his significance, remind him about his responsibility for a successful project. 如果您的老板固执己见,那么作为开发人员的美好时光就荡然无存了,他只想展示自己的重要性,就此提醒他,他对成功项目的责任。 For example, tell him he is an architect and a person who makes the final decision and you will follow it because he is the one who is responsible for the project success but on the other hand it's your responsibility to be proactive and express any concerns you have to help your boss make the right decision. 例如,告诉他他是建筑师,是一个做出最终决定的人,您将遵循该决定,因为他是负责项目成功的人,但另一方面,您有责任积极主动并表达您的任何担忧必须帮助您的老板做出正确的决定。 This should make your boss think again as he doesn't want to fail the project because of his "gut feeling". 这应该使您的老板再三考虑,因为他不想因为他的“胆量”而失败。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM