OO问题新手
我的问题与 Windows 表单有关
假设我有一个用于客户和订单的组合框,根据在这些组合框中所做的选择,我为所有订单详细信息填充数据网格。
我对数据网格行中的双击事件感兴趣。
事件发生后,可能会发生 2 件事:
- 记录被删除。
- 一个或两个组合框已更改。
由于没有面向对象的经验,我正在代码隐藏中处理所有逻辑。
这是错误的做法吗?如果满足所有条件,我是否应该创建一个返回布尔值的类,是否取消事件或执行其他操作?
如果我创建一个处理该逻辑的类,那么该类需要引用数据网格和所有关联的控件及其先前值和当前值。
我只是很困惑。
My question pertains to windows forms
Let's say I have a combobox for customer and orders, and depending on the selection made on those comboboxes I populate a datagrid for all the Order details.
I am interested in a double click event within the datagrid row.
Upon the event 2 things can happen:
- the record was deleted.
- one or both combobox was changed.
With no OO Experience, I am handling all that logic in the code-behind.
Is that a wrong thing to do? Should I be creating a class that returns a boolean whether to cancel the event or do something else if all the conditions are satisfied?
If I create a class that handles that logic then that class needs reference to datagrid and all the associated controls and their Previous values and current values.
I am just confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是一个面向对象的问题:有关模式的更多信息。
如果我是你,我会查看 MVC< /a>(模型视图控制器)、MVP(模型视图呈现器)等。 Martin Fowler 是该主题的主要权威之一。
MVVM 在 WPF 中很流行 - 不确定数据绑定是否适合 Forms 中的情况。
关键的事情之一是,如果您的逻辑与显示模块分开,测试就会容易得多。
I'm not sure that this is an OO question: more about patterns.
If I were you, I'd look at MVC (Model View Controller), MVP (Model View Presenter) and so on. Martin Fowler is one of the main authorities on this subject.
MVVM is popular in WPF - not sure if databinding is up to it in Forms.
One of the key things is that testing is so much easier if you have logic separate from the display gubbins.
面向对象的做事方式是没有人可以一次性告诉你的。这是一种全新的思维范式,涉及如何通过很少的交互对象来解决问题。这些对象来自您正在为其创建解决方案的问题域。
从问题中,我可以轻松地选出至少两个问题域对象 - 一个是“客户”,另一个是“订单”。
可能您的“Order”类由“OrderItem”的各种对象组成,“OrderItem”由对“Product”之一的引用、数量和可能是价格组成。
如果这有点难以理解,我很确定您至少会有一个包含提供数据持久存储的表的数据库。您拥有的表(在许多情况下)可以对应于您需要设计的实际类。
您不必设计实际上与数据网格和其他控件一起使用的单独的类,这些类可以保留在后面的代码中。但是您的所有业务域对象以及可以对这些对象执行的操作都必须封装到类中。
Object oriented way of doing things is something that no one can tell you in just a single shot. It's a whole new paradigm of thinking on how a problem can be solved in terms of few interacting objects. These objects are from the problem domain for which you are creating a solution.
From the question, I can easily pick out atleast two problem domain objects - one would be "Customer" and the other "Order".
May be your "Order" class is composed of various objects of "OrderItem" which is composed of a reference to one of the "Product", quatity and may be the price.
If this is getting a bit hard to understand, I'm pretty sure that you would atleast have a database with tables that provides persistent storage of data. The tables that you have, (in many cases) can correspond to the actual classes that you need to design.
You dont' have to design seperate classes that are actually going to work with the datagrid and other controls, that can stay be in the code behind. But all your business domain objects and the operations that can be performed on these objects must be encapsulated into classes.