locked
Are classes necessary in single-user app? RRS feed

  • Question

  • Trying to learn vb.net.  

     

    If an application is for a single-user only, is it still good programming practice to use classes?  All this app will do is take input and write it to a SQL database.  Using a reporting function, the user will be able to request many reports using this data.

      

    Thanks


    Kris Hood

    Wednesday, July 3, 2013 7:42 PM

Answers

  • Trying to learn vb.net.  

     

    If an application is for a single-user only, is it still good programming practice to use classes?  All this app will do is take input and write it to a SQL database.  Using a reporting function, the user will be able to request many reports using this data.

      

    Yes.  You should always use classes to keep your code separate and organized.  It doesn't matter if it's a single-user or multi-user application, or if there are multiple developers.

    Even if it's a single-user app written just by you, just for you, it's useful.  6 months later, when you have to reuse or change the application, having clean organization will save you a lot of time.

    In addition -while it may seem like classes make things more complex (when you're learning), as you learn VB.Net better, you'll find that having good separation of your code actually makes writing the code faster, too...


    Reed Copsey, Jr. - http://reedcopsey.com - If a post answers your question, please click Mark As Answer on that post. If you find a post helpful, please click Vote as Helpful.

    • Proposed as answer by Frank L. Smith Wednesday, July 3, 2013 7:49 PM
    • Marked as answer by db_dweeb Wednesday, July 3, 2013 8:02 PM
    Wednesday, July 3, 2013 7:44 PM

All replies

  • Trying to learn vb.net.  

     

    If an application is for a single-user only, is it still good programming practice to use classes?  All this app will do is take input and write it to a SQL database.  Using a reporting function, the user will be able to request many reports using this data.

      

    Yes.  You should always use classes to keep your code separate and organized.  It doesn't matter if it's a single-user or multi-user application, or if there are multiple developers.

    Even if it's a single-user app written just by you, just for you, it's useful.  6 months later, when you have to reuse or change the application, having clean organization will save you a lot of time.

    In addition -while it may seem like classes make things more complex (when you're learning), as you learn VB.Net better, you'll find that having good separation of your code actually makes writing the code faster, too...


    Reed Copsey, Jr. - http://reedcopsey.com - If a post answers your question, please click Mark As Answer on that post. If you find a post helpful, please click Vote as Helpful.

    • Proposed as answer by Frank L. Smith Wednesday, July 3, 2013 7:49 PM
    • Marked as answer by db_dweeb Wednesday, July 3, 2013 8:02 PM
    Wednesday, July 3, 2013 7:44 PM
  • I completely agree with Reed.

    I don't know how far along you are with your knowledge yet, but - you are aware that, for example, "Form1.vb" IS a class itself, right?


    Please call me Frank :)

    Wednesday, July 3, 2013 7:50 PM
  • Both forms and their controls are classes, aren't they?

     

    For some reason, that's easy to understand but creating my own is not.  It's like Reed stated, it seems to make things more complex.  I created a very simple app to enter your last name, first name, and favorite color, using a single class.  You then click on a button and what you entered is displayed back in a message box.  I understand what the code is doing but not why it's better to do it this way. 

     

    Thanks for your replies.


    Kris Hood

    Wednesday, July 3, 2013 8:02 PM
  • Both forms and their controls are classes, aren't they?

    For some reason, that's easy to understand but creating my own is not.  It's like Reed stated, it seems to make things more complex.  I created a very simple app to enter your last name, first name, and favorite color, using a single class.  You then click on a button and what you entered is displayed back in a message box.  I understand what the code is doing but not why it's better to do it this way. 

    Thanks for your replies.


    Kris Hood

    Someone asking, essentially "tell me all about classes" is akin to someone asking "tell me all about physics". It's a bit broad! ;-)

    A class is both an organizational tool like has been discussed (as is its big brother, a Namespace), but moreover, it's a veritable template, or a 'set of instructions of what to do once instantiated'.

    It's definitely a lot to take in - at once - but over time, you'll sort of get the hang of it (even without trying to) just by consuming and manipulating them.

    For what it's worth. :)


    Please call me Frank :)

    Wednesday, July 3, 2013 8:17 PM
  • Both forms and their controls are classes, aren't they?

     

    For some reason, that's easy to understand but creating my own is not.  It's like Reed stated, it seems to make things more complex.  I created a very simple app to enter your last name, first name, and favorite color, using a single class.  You then click on a button and what you entered is displayed back in a message box.  I understand what the code is doing but not why it's better to do it this way. 

     

    Thanks for your replies.


    Kris Hood

    Hi Kris,

    In the case you describe there would be nothing wrong with declaring three fields at the form level and just tracking first name, last name, and favorite color that way.  If the application will only ever care about one user's information, and will only use it in a limited fashion, then there's nothing wrong with this design.

    However, if there is any chance that you will ever need to know more than one user's name and favorite color, or if you need to perform a lot of different function on that information then you should consider encapsulating everything that has to do with the user's information and the actions against it in an object.

    Suppose that you decide you need a second form to let the user change their favorite color with a fancy color picker control you designed.  You could just pass the FavoriteColor field from your main form to the edit form, but suppose you want to display the name too?  Do you pass all three fields to the edit form?  You could, since three parameters is still reasonable for a method signature, but you could also just pass an single "User" object which contained the favorite color and the name.

    So, the more complex the object, the greater the advantage of using a class to encapsulate it.  Make sense?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, July 4, 2013 4:14 AM