OOP Question

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I have always developed in VB, and I usually end up programming all events and related methods in the form (if I have a GUI application). I was thinking whether there is a better way of doing this, which is also more OOP. By reading a Java book, the author said that in Java it is good practice to add a class that manages all form's events and related methods. But since that book is quite old, I was wondering, whether this has been superseded by other approaches.

Thank you very much.
Mike
 
Mike,

As the saying goes, "There is more than one way to skin a cat".

By developing all of the logic in your application in the form, it was
difficult to use this logic elsewhere if the need ever arose. You would
have to copy/paste code, which has the effect of providing two codebases you
now have to maintain.

By encapsulating your logic in an object, and then having the form
access the object (which is embedded in another assembly, for easier reuse),
you are basically allowing the functionality in your object to be used in
other places, and not tied to the UI. Reuse is always a good thing.

Think of your components like batteries. You can take the batteries,
and apply them to many, many devices, and it all works. These devices are
usually preferable as opposed to the same device with some other custom
power source which can't be replaced (you have to throw the whole item out
and get a new one).

The same applies here. How much you want to do it depends on how much
you think you will reuse your code in other places.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hi,

I have always developed in VB, and I usually end up programming all events
and related methods in the form (if I have a GUI application). I was
thinking whether there is a better way of doing this, which is also more
OOP. By reading a Java book, the author said that in Java it is good
practice to add a class that manages all form's events and related methods.
But since that book is quite old, I was wondering, whether this has been
superseded by other approaches.

Thank you very much.
Mike
 
Thanks! Yes, your clarifications are very helpful.

Mike


Mike,

As the saying goes, "There is more than one way to skin a cat".

By developing all of the logic in your application in the form, it was
difficult to use this logic elsewhere if the need ever arose. You would
have to copy/paste code, which has the effect of providing two codebases you
now have to maintain.

By encapsulating your logic in an object, and then having the form
access the object (which is embedded in another assembly, for easier reuse),
you are basically allowing the functionality in your object to be used in
other places, and not tied to the UI. Reuse is always a good thing.

Think of your components like batteries. You can take the batteries,
and apply them to many, many devices, and it all works. These devices are
usually preferable as opposed to the same device with some other custom
power source which can't be replaced (you have to throw the whole item out
and get a new one).

The same applies here. How much you want to do it depends on how much
you think you will reuse your code in other places.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hi,

I have always developed in VB, and I usually end up programming all events
and related methods in the form (if I have a GUI application). I was
thinking whether there is a better way of doing this, which is also more
OOP. By reading a Java book, the author said that in Java it is good
practice to add a class that manages all form's events and related methods.
But since that book is quite old, I was wondering, whether this has been
superseded by other approaches.

Thank you very much.
Mike
 
Back
Top