gpt4 book ai didi

java - bloated class 和 tagged class 有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:53:07 24 4
gpt4 key购买 nike

正如我在 Effective java 中读到的那样

Bloated class hierarchies can lead to bloated classes containing many methods that differ only in the type of their arguments, as there are no types in the class hierarchy to capture common behaviors.

Link

A bloated class often has many special cases: attributes or behavior valid for some instances but not others. Often programmers attempt to deal with special cases by introducing type tags.

标记类与膨胀类之间存在相似性,如 Effective java 中提到的那样:

a class whose instances come in two or more flavors and contain a tag field indicating the flavor of the instance. instances are burdened with irrelevant fields belonging to other flavors.

因此得出结论,这两个类可能都有标签类型/字段,并且两个类都有如此多的实现(在一个类中模拟了如此多的特性)。

我对这些术语感到困惑,我想知道这两个 Bloated class 和 Tagged class 之间有什么区别??

最佳答案

  • 臃肿的类是臃肿的(见下文)。
  • 一个标记类有一个或多个标记。
  • 带标签的类可能是臃肿的,而臃肿的类不一定是带标签的。

“臃肿”是(有点)主观的,“标记”是微不足道的识别。 “膨胀”可以指代很多东西;关注点分离不佳、缺少封装、抽象级别不同等。

“标记”的主观性较低,因为会有一个字段定义功能分离、抽象等。

关于java - bloated class 和 tagged class 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29167725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com