以下方法的设计模式名称

name of design pattern for below approach

我有开源代码,我的目标是在不破坏开源结构的情况下向这段代码添加一些功能。 例如

class OpensourceClass{
       String getValue(){
         return "";
       }
   }

所以我创建了一个接口 int class 并且在开源 class

中引入了该接口的一个实例
 class OpensourceClass{
       public static interface userImpl{
          String getValue();
       }

        private static userImpl obj;

      public static  void setUserImpl(userImpl ob){
          obj=ob;
      }
       String getValue(){
           if(userImpl)
              return userImpl.getValue();
             return "";
      }
    }

只是想知道这是哪个设计模式.. 是策略模式吗

是的。这是 Strategy 模式。

这是Strategy (Policy) design pattern. Depending on the context it can also be called the State pattern. These two patterns are pretty similar, you can check this question for more details: What is the difference between Strategy Design pattern and State Design pattern?

更广泛的术语是 Inversion of control。使用策略设计模式是实现控制反转的基本技术之一。

此外,通过尝试使您的开源 class 可扩展,您可以遵循 Open/closed principle. As stated in this 文章,策略模式是实现 Open/Closed.

的方法之一