views:

108

answers:

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.

+2  A: 

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.

serialhobbyist
A: 

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.

Trainee4Life