不适用反射如何一个接口获取到多态类
时间: 2024-06-03 16:10:24 浏览: 58
一个接口获取到多态类的方法是使用抽象工厂模式或者工厂方法模式。这两种模式都可以通过接口返回不同的对象实例来达到多态的效果。在抽象工厂模式中,每个具体工厂都会返回一组相关的对象实例,而在工厂方法模式中,每个具体的工厂只返回一个对象实例。无论使用哪种模式,都可以通过接口来访问不同的对象实例。不适用反射的话,可以在工厂或者抽象工厂中使用 switch/case 语句或者条件判断语句来获取不同的对象实例。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)