接口+基类 - 这是什么模式?
我定义了一个由基类实现的接口。该基类提供基本功能。现在我有多个实现来实现基类并通过更多细节扩展这些功能。当我调用这些多个实现时,我将这些实现强制转换为接口(在基类中实现)。
是否有描述此类接口使用的模式?或者说这种架构适得其反?
问候
I have defined an interface that is implemented by a base class. This base class provides basic functionalities. Now I have multiple implementations that implement the base class and expand these functionalities with more specifics. When I call those multiple implementations I cast the implementations to the interface (that is implemented in the base class).
Is there any pattern where this type of interface useage is described? Or is this kind of architecture counterproductive?
Greetings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的基类是抽象的,那么就有一种已知的模式,即抽象类模式(按其名称之一)。您的用法是有效的,因为它隐藏了基类引入的不属于接口实现的一部分的恶作剧,从而保护客户端代码免遭滥用您的类型。
有关此文档的更多信息。
If your base class is abstract, then there's a known pattern, The Abstract Class Pattern by one of its names. Your usage is valid because it hides the shenanigans introduced by the base class which are not part of the interface implementation, thus protecting client code from misusing your types.
More on this document.