Question Classes, Best practices question

gbalcom

Member
Joined
Oct 20, 2016
Messages
12
Location
Georgia
Programming Experience
Beginner
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.
 

Nybbler13

New member
Joined
Jan 15, 2016
Messages
1
Programming Experience
10+
You might consider creating a single class with all the common functionality and then create subclasses by inheriting from it.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,402
Location
Sydney, Australia
Programming Experience
10+
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.
 
Top Bottom