接口可以跨 vb.net 中的聚合/复合类实现吗?
VB.NET .NET 3.5
我有一个名为 Package 的聚合类,作为运输系统的一部分。包包含另一个类 BoxType 。 BoxType包含有关用于运送包裹的盒子的信息,例如盒子的长度、宽度等。
包裹有一个名为 GetShippingRates 的方法。此方法调用单独的帮助程序类 ShipRater,并将 Package 本身作为参数传递。 ShipRater 检查包裹和 BoxType,并返回可能的运费/方法的列表。
我想要做的是构造一个接口 IRateable,它将提供给辅助类 ShipRater。因此,
Class ShipRater
Sub New(SomePackage as Package)
End Sub
End Class
我们不会这样做:
Class ShipRater
Sub New(SomeThingRateable as IRateable)
End Sub
End Class
但是,ShipRater 需要来自 Package 及其聚合 BoxType 的信息。如果我编写一个接口 IRateable,那么如何使用 BoxType 属性来实现该接口的部分内容?这可能吗?
VB.NET .NET 3.5
I have an aggregate class called Package as part of a shipping system. Package contains another class, BoxType . BoxType contains information about the box used to ship the package, such as length, width, etc. of the Box.
Package has a method called GetShippingRates. This method calls a separate helper class, ShipRater, and passes the Package itself as an argument. ShipRater examines the Package as well as the BoxType, and returns a list of possible shipping rates/methods.
What I would like to do is construct an Interface, IRateable, that would be supplied to the helper class ShipRater. So instead of:
Class ShipRater
Sub New(SomePackage as Package)
End Sub
End Class
we would do:
Class ShipRater
Sub New(SomeThingRateable as IRateable)
End Sub
End Class
However, ShipRater requires information from both the Package and its aggregate, BoxType. If I write an interface IRateable, then how can I use the BoxType properties to implement part of the Interface? Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该接口不需要了解有关如何聚合调用的任何信息(可以假设并非所有可计费项目都需要聚合调用)。将聚合(通过委托)调用留给
Package
:The interface wouldn't need to know anything about how you aggregate the calls (it could be assumed that not all Rateable items need to agregate calls). Leave the aggregation (via delegation) calls up to
Package
:当然。只需将所需的调用委托给聚合的 BoxType 即可。抱歉,C#:
Sure. Just delegate required calls to an aggregated
BoxType
. Sorry for C#: