You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ljluestc (via GitHub)" <gi...@apache.org> on 2023/06/27 07:21:10 UTC

[GitHub] [dubbo] ljluestc commented on issue #5538: 使用抽象类作为dubbo接口的入参,不能进行泛化调用

ljluestc commented on issue #5538:
URL: https://github.com/apache/dubbo/issues/5538#issuecomment-1608937759

   使用接口而不是抽象类:定义一个代表各种实现共享的公共行为的接口,而不是使用抽象类。 然后,你可以在方法签名中使用接口类型并根据接口契约执行操作。 这样就不需要知道具体的实现类了。
   
   使用通配符类型或泛型类型参数:你可以使你的方法接受通配符类型 (?) 或泛型类型参数 (T) 来表示抽象类。 这允许调用者提供抽象类的任何实现。 但是,请记住,你可能需要使用反射或其他机制来处理未知的实现类。
   
   引入工厂或构建器模式:你可以定义一个工厂或构建器模式来创建抽象类的实例,而不是直接使用抽象类。 工厂或构建器可以封装根据某些标准选择适当的实现类的逻辑。 这样,你可以获取抽象类的实例,而无需显式知道它们的实现。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org