2

I have started learning VB.NET lately and have read 1 Step-By-Step beginners book and am now moving onto an Advanced book and both have failed to really explain what the point in modules and classes are.

Are modules and classes simply ways to organize functions and sub-procedures?

E.g. A class named MyMathClass which contains 100 different Math functions would be easier to skim through compared to a file with 100 non-related functions.

Chris
  • 512
  • 1
  • 16
  • 33
  • Don't mix-up classes with a collection of functions. I fear that the books haven't only failed in explaining what modules are but - much more important - what classes and objects are in an [object-oriented context](http://oreilly.com/catalog/objectvbnet/chapter/ch01.pdf). – Tim Schmelter Aug 22 '11 at 22:28
  • [Here](http://msdn.microsoft.com/en-us/library/dd460654.aspx) are more informations on OOP in .NET. By the way, a module really is like a collection of functions for a speific context(f.e. Math-Algorithms). But i would avoid Modules at the first place because they prevent understanding the OOP-concepts since there is no (public) constructor and all functions/properties are [shared](http://msdn.microsoft.com/de-de/library/zc2b427x.aspx). – Tim Schmelter Aug 22 '11 at 22:37

2 Answers2

4

Modules are a VB6 left-over. Required for compatibility, there's little point in using them when you program from scratch. Biggest problem with them is that they pollute the global namespace. That might be nice at first but it scales very poorly. They are however still used to create extension methods, adding those to the global namespace is the intended effect.

Grokking classes requires understanding Object Oriented Programming. That cannot reasonably fit in an SO post, there are many introductory books that help you in the grok.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 2
    Modules are the equivalent of C# static classes and the only way to write extension methods in VB, so they do have uses for new programs still. – Gideon Engelberth Aug 22 '11 at 23:11
0

I would agree with Tim Schmelter. While there still are uses for modules for extension methods, since you are learning OOP principles, stick to using classes. With classes, you can really take advantage of the 3 pillars of OOP (Encapsulation, Inheritance, and Polymorphism) without thinking about modules which can add to confusion at this stage of learning.

5StringRyan
  • 3,604
  • 5
  • 46
  • 69