Data Objects: Classes vs. Windows

One of the things that attracted me to RB 20 years ago was the idea that you could design your UI and then ‘wire it up’ under the hood with the logic that would perform some sort of action upon the data entered into the fields in the UI. In this way, the Window provided the structure for the object… fields stored the data that might otherwise be stored in properties.

On the other hand, it seems quite common to create Classes with properties and methods. The class is then instantiated and used to populate the UI. Why? Doesn’t this double the amount of work it takes to create your window?

For example, consider a simple CRUD scenario in which a list of products is managed via two windows: a ProductListWindow with a listbox and a ProductWindow with a form for creation and editing of products in the list. Do you also create a Product class with all the properties and methods associated with products? Or, do you simply use the ProductWindow since it already has a field for every property? It seems silly, to me, to write all the code to populate the Product class… and then write the code again to populate the fields in the window from the properties in the class.

Unless I’m missing something here… I’m inclined to simply use the ProductWindow as my class. Can anyone think of a good reason not to?

Yes. Later extensions or a version for a different platform. With a model view controller based structure, you just wire up controller and view and leave the rest untouched.
If you are sure you will never include different platforms and that the class structure of your app will not expand wildly, just go on. This approach is often faster at first but may get complicated once the class logic expands.

agree, just a visualization of a class property for edit would be very useful.

var a as string = "Input Me",x,y,width,height
  • a simple load save interface^^ i don’t care this stupid old database concept.

It’s a little more work now, but it will save you a ton of work in the future.