开发者

Interface + Baseclass - What pattern is this?

开发者 https://www.devze.com 2023-02-03 14:51 出处:网络
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 func

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 useag开发者_如何转开发e is described? Or is this kind of architecture counterproductive?

Greetings


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消