C# 设计模式

发布于 2024-11-06 20:25:08 字数 125 浏览 1 评论 0原文

我是 C# 编程新手,我遇到了三个事件,例如鼠标键按下、向上和拖动。

在所有这些事件中,我需要重新绘制屏幕。有没有任何设计模式可以做到这一点。

因为,我需要在每个事件上重复调用这个 Repaint 方法?

I'm new to C# Programming, I'm having three events like Mouse Key Down,Up and Drag.

On all this events I need to repaint the screen. Is there any Design pattern to do this.

Since, I need to call this Repaint method repeatedly on each events??

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

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

发布评论

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

评论(1

下壹個目標 2024-11-13 20:25:08

您有三个事件,并且想要从所有事件中调用 Repaint。这是三行代码。您尝试隐藏重绘所做的任何抽象都会花费您超过三行代码,因此您需要一个更复杂的用例,然后才能证明比仅仅放置 Repaint 更复杂的解决方案是合理的进入您的三个事件处理程序中的每一个。

编辑:

我想补充一点,你的问题引起了很大的争议,我个人不同意。我认为这是一个简单而真诚的问题,而且问得很清楚。这实际上是一个很好的初学者设计问题:“我应该在这样那样的情况下使用抽象吗?”所以,不,我认为你不应该在这种情况下这样做。但这对你有好处,因为你每次有机会就尝试使用抽象,不用担心,因为你很快就会得到很多合理的理由!

You have three events and you want to call Repaint from all of them. That's three lines of code. Any abstraction you do to try to hide that repainting is going to cost you way more than three lines of code so you need a much more complicated use case before you can justify a more complex solution than just putting Repaint into each of your three event handlers.

Edit:

I want to add that you are taking a lot of heat for your question and I for one do not agree. I think It's a simple sincere question and one asked clearly. It's actually a great beginner design question: "Should I use abstraction in such-and-such situation?" So, no, I don't think you should in this situation. But good for you for trying to use abstraction every chance you get and don't worry because you will get plenty of legitimate reasons soon enough!

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