[英]Proper design of Java Classes
我的问题是我应该做counterbore
(一凹孔的板)的财产plate
还是应该counterbore
是一个属性joint
我为工程分析程序提供以下课程:
Plate
Bolt
Washer
Nut
Material
Coating
然后,我有代表各种关节的课程
TappedJoint (a joint were the bolt is threaded into the bottom plate) will have:
Plate topPlate
Plate bottomPlate
Bolt bolt
Washer topWasher
BoltedJoint
Plate topPlate
Plate bottomPlate
Bolt bolt
Nut nut
Washer topWasher
Washer bottomWasher
沉孔仅适用于topPlate
但我需要验证用户输入的板厚度大于沉孔的深度。 我是否只是在bottomPlate中将沉孔设置为null,还是将沉孔属性放入联合类中更好? 还是我应该使用其他模式,例如子类?
我将涂层和材料作为属性添加到每个零件,因为添加到接缝将太冗长,即:
BoltedJoint
Plate topPlate
Plate bottomPlate
Coating topPlateTopSurface
Coating topPlateBottomSurface
Coating bottomPlateTopSurface ...etc
我可能可以使它适用于任何一种情况,但也许它们是更好的设计?
我认为,如果将counterbore
作为Joint
属性,那么Plate
和Bolt
都可以访问特定于每个Joint
的属性。 这样,螺栓无需访问Plate对象即可找到孔。
如果我正确地理解了上下文,则counterBore
是Joint
对其topPlate
要求。 在这种情况下,它应该是Joint
的属性(可能取自Bolt
或其他指定的东西),并且如果其厚度不足, Joint
应该拒绝topPlate
。
如果counterBore
是Plate
的物理属性(即Plate
实际上具有钻孔的沉孔),则它也应该是Plate
的属性。 但是Joint
仍然需要它作为其topPlate
的要求。
希望有道理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.