有这样的设计模式吗?怎么称呼呢?

发布于 2024-09-24 15:21:23 字数 386 浏览 4 评论 0原文

我有这样的设计:

public interface MyInterface {
    public abstract List<Sth> getSth();
}

public class MyConcreteImplementation implements MyInterface {
    private ConcreteSth mSth = new ConcreteSth();

    public List<Sth> getSth(){
        return mSth.getSth(additionalParams); 
    }
}

上面代码的目的是提供从其他类调用的统一方法。

这也能称为模式吗?如果可以怎么命名呢?

I have such design:

public interface MyInterface {
    public abstract List<Sth> getSth();
}

public class MyConcreteImplementation implements MyInterface {
    private ConcreteSth mSth = new ConcreteSth();

    public List<Sth> getSth(){
        return mSth.getSth(additionalParams); 
    }
}

Purpose of code above is to provide unified method to be called from other classes.

Can this be called a pattern? If so how to name it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

忆悲凉 2024-10-01 15:21:23

在我看来,它就像一个适配器。它将ConcreteSth 适配为MyInterface

不管怎样,如果它完成了您期望的工作,您应该询问它是否只是出于好奇而存在的模式。

It looks to me like an Adapter. It adapts ConcreteSth to MyInterface.

Anyway, if it does the work you expect from it, you should be asking about whether it's a pattern only out of curiousity.

梦年海沫深 2024-10-01 15:21:23

您在这里只是遵循基本的面向对象设计。对我来说,这看起来很简单组合,如果您真的热衷于设计模式,我可以扩展它成为委托的形式。

You are just following basic object oriented design here. This looks like simple Composition to me and if you are really keen on a design pattern I could stretch it to being a form of delegate.

万人眼中万个我 2024-10-01 15:21:23

适配器

上面代码的目的是提供从其他类调用的统一方法。

这听起来真的很像适配器。您希望有一个适合您的界面的类。这里的接口是MyInterface,适配者是ConcreteSth

Adapter

Purpose of code above is to provide unified method to be called from other classes.

That's really sound like Adapter. You want to have a certain class adapted to your interface. The interface here is MyInterface and the adaptee is ConcreteSth.

雪花飘飘的天空 2024-10-01 15:21:23

我将其称为适配器:它在现有接口(即 ConcreteSth)周围包装了另一个方法(MyInterface.getSth),而不更改功能。

I would call it an Adapter: it wraps another method (MyInterface.getSth) around an existing interface (i.e. the ConcreteSth), without changing the functionality.

冰葑 2024-10-01 15:21:23

工厂方法?

工厂方法模式的本质是“定义一个用于创建对象的接口,但让子类决定实例化哪个类。工厂方法让类将实例化推迟到子类”。

http://en.wikipedia.org/wiki/Factory_method_pattern

Factory method?

The essence of the Factory method Pattern is to "Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses."

http://en.wikipedia.org/wiki/Factory_method_pattern

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文