软件设计只包含界面?

发布于 2024-12-05 18:40:40 字数 311 浏览 3 评论 0原文

在软件设计中,仅用接口描述类交互时,这是一个好方法吗?如果是,我应该始终使用这种方法吗?

我必须设计具有高可测试性的类库(我使用C#)。

该库有一个外观和一些在后台具有不同交互作用的类。

在优化这个库以获得良好的可测试性的情况下,我用接口替换了大部分类。

当我这样做时,我在连接图(Visual Studio 类图)中只看到了接口。

这是我的问题的正常决定吗?或者应该有其他方法?

P/S:也许这是软件设计中众所周知的方式,但我在我拥有的书中找不到一些确认。

Is it good approach when in software-designing the class interactions are describe only with interfaces? If yes, should I always use this approach?

I must design class library that should have a high testability (I use C#).

This library have one facade and some amount of classes with different interactions in the background.

In the case of optimizing this library for good testability I've replace most part of my classes with interfaces.

And when I did this, I saw in a connection diagram (Visual Studio class diagram) only interfaces.

Is it normal decision of my problem? or there should be some another approach?

P/S: Maybe it's well known way in software-design but I can't find some confirmation in books that I have.

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

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

发布评论

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

评论(3

魂ガ小子 2024-12-12 18:40:40

是的,这是一个很好的做法。它允许您专注于每个类的职责,而无需关心实现细节。它允许您查看方法调用堆栈,并且正如您所说,提供了高水平的可测试性和可维护性。据我所知,你走在正确的轨道上:)

Yes this is good practice. It allows you to focus about the responsibilities of each class without getting concerned with implementation details. It allows you to see the method call stack and as you say gives a high level of testability and maintainability. You're on the right track as far as I see :)

﹉夏雨初晴づ 2024-12-12 18:40:40

是的,这通常是一个很好的做法。

我建议您阅读一本好的设计模式书籍,例如这本书

它是针对 Java 开发人员的,但作为 C# 开发人员,我可以轻松理解所有示例。

Yes, that is generally a good practice.

I would recommend you to read a good design patterns book, for example this one.

it is targeted for Java developers but I had no trouble understanding all the examples as a C# developer.

Spring初心 2024-12-12 18:40:40

通过使用接口,您可以将应用程序分解为子系统,使其可维护且易于扩展。一些用例可以是:

  • 应用程序可能需要与多个 Web 服务端点进行通信,以完成相同的功能,例如来自不同提供商的直接计费或支付接口

  • 数据访问层类,这些类使用不同的驱动程序对不同的数据库执行 SQL。

  • 使用同一队列中的同一线程池处理实现同一接口的不同对象

By using interfaces you can decompose your applications into subsystems to make it maintenable and easily expandable. Some uses cases can be:

  • application may need to communicate more than one web service endpoints to to fullfill same functions such as direct billing or payment interfaces from different providers

  • data access layer class that execute SQLs to different Databases with different drivers.

  • processing different objects that implements the same interface using the same thread pool from the same queue

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