Results 1 to 4 of 4

Thread: Classes, Best practices question

  1. #1
    gbalcom is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Oct 2016
    Location
    Georgia
    Posts
    12
    Reputation
    8

    Question Classes, Best practices question

    Hello,
    I'm writing my first application that I will make use of classes in. I've read some on Object Oriented programming and would like to take my code to the next level (over standard modules). Let's say I have 3 distinct email types that my application will produce (Type A, B, and C).

    I'm tempted to create a class for each type (clsA, clsB, and clsC). But, doing so would create redundant code in the 3, unless I can reference 1 standard module for the boiler plate functions.

    So, the question is: Can I reference the Standard Module from each class, and if I can, should I? Perhaps there is a better way to handle this?

    I'm sure this is a very rudimentary question for most, sorry if I placed it in the wrong section.

  2. #2
    Nybbler13 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jan 2016
    Posts
    1
    Reputation
    0
    You might consider creating a single class with all the common functionality and then create subclasses by inheriting from it.

  3. #3
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,801
    Reputation
    1705
    Quote Originally Posted by Nybbler13 View Post
    You might consider creating a single class with all the common functionality and then create subclasses by inheriting from it.
    That is exactly what should be done. Consider the controls you probably already use in your applications. There is a Control class that contains all the common functionality that every control will have and then each individual control class inherits that base class, adding their own specific functionality. In that case, there are other intermediate classes too. In fact, controls are so varied and numerous that there are several layers of inheritance. In your case though, you probably only need one base class and then three derived classes. That said, if two of your email types share some functionality that the third doesn't, you might create a common base type for them that inherits the class that provides the functionality common to all three.

  4. #4
    gbalcom is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Oct 2016
    Location
    Georgia
    Posts
    12
    Reputation
    8
    Excellent, thanks guys! For the benefit of others, here is an article I found after your responses which I think describes the process pretty well. (even though it's a 16 year old article)

    https://msdn.microsoft.com/en-us/library/ms973803.aspx

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •