简体   繁体   English

是桥梁还是立面图案?

[英]Is it a bridge or facade pattern?

And I have C interface which contains A and B interfaces. 我有C接口,其中包含A和B接口。

Which pattern is this implementing? 这是实施哪种模式?

public class Service : IService
{
    private readonly IWebServiceProvider _serviceProvider;
    private readonly IDatabaseProvider _dbProvider;

    public Service(IWebServiceProvider serviceProvider, IDatabaseProvider dbInteractionsProvider)
    {
        _serviceProvider = serviceProvider;
        _dbInteractionsProvider = dbInteractionsProvider;
    }

    public IEnumerable<Company> CompanySearch(string name)
    {
        return _dbProvider.CompanySearch(name);
    }

    public ValidationResult ValidateUser(Data data)
    {
        var result = _serviceProvider.ValidateUser(new ValidationData()
        {
            Company = data.CompanyName,
            Password = data.Password,
            Login = data.Login
        });
        return new ValidationResult() { ErrorMessage = result.ErrorMessage };
    }

    public bool ResetPassword(ResetPassword resetPassword)
    {
        throw new System.NotImplementedException();
    }

    public string GenerateURL(int id)
    {
        return _serviceProvider.GenerateURL(id);
    }
}

您提供的代码实现了IoC(控制反转)模式。

To call it the bridge pattern, you need to see evolution paths along abstraction and implementation. 要称其为桥接模式,您需要查看抽象和实现的演进路径。 Here, implementation evolution (by using different service providers and db providers) paths are seen. 在这里,可以看到实现的发展(通过使用不同的服务提供者和数据库提供者)路径。 But abstraction evolution is not seen in the code given (even though it is possible). 但是,在给出的代码中看不到抽象演化(即使可能)。

Also, the service class uses two implementation classes related to two different matters. 此外,服务类使用与两个不同问题相关的两个实现类。 A bridge would ideally represent one thing. 理想情况下,一座桥代表一件事。

So this is more closer to a facade. 因此,它更接近外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM