【发布时间】:2017-12-05 08:04:56
【问题描述】:
以下是 sourcemaking.com 中此模式的示例:
https://sourcemaking.com/design_patterns/private_class_data
有两个例子,划掉的主类和包含数据类的主类。
我的问题只是以下内容与链接中给出的正确实现之间有什么区别:
public class MainClass {
private final <Type> attribute1;
private final <Type> attribute2;
private final <Type> attribute3;
public MainClass(<Type> attribute1, <Type> attribute2, <Type> attribute3 {
this.attribute1 = attribute1;
this.attribute2 = attribute2;
this.attribute3 = attribute3;
}
}
干杯
【问题讨论】:
-
您的问题中缺少泛型类型定义
-
我认为从业务逻辑外部化数据类的好处在更大的类中变得更加明显。这个小班并不能真正起到示范作用。
-
请注意,模式不是来自 GoF。在我看来,它更像是一种反模式。
标签: java design-patterns encapsulation design-principles