goomba454 goomba454 - 3 months ago 9x Question

Using my own Objects vs just using a Module

I have read why to use classes, but I don't understand how it makes my program better?

My example: I made a class called "PanelList" and within it are several subs and a few functions that all use related information that will Arrange panels, resizes panels, and Save/Load information from a database. I access it from my main form using:

dim myObj as new PanelList()
myObj.Gap = 20
myObj.ArrangePanels(Panel1, Panel2)

Why is that better than if I would just do something like this from a module which seems much more condensed and I don't have to create a new instance:

ArrangePanels(Panel1, Panel2, 20)

I would think creating a new instance of an object would take more resources, and if I need to create several objects it starts to make my code look unorganized in my view?

So why would I use my own Objects??


The function you describe in your question isn't really object-oriented, so indeed it doesn't sound like it would make much sense to create an object for it. It's just a helper function that you want to put somewhere.

Objects are exactly that... objects. They are "things" which are described semantically by attributes and operations. For example, you might have a Person object. It's not just a dumping ground for random functions, but rather a discrete instance representing a "person". It has data describing that instance of a person, it has operations that can be performed on or by a person, etc.

If you're not doing any object-oriented programming then, no, you don't really need objects. But if your domain space has discrete semantic concepts of "things" which can be packaged into objects, then it would make sense to do so.