473,788 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Module vs Class

Hi,

I am a VB.net beginner, I do not know what are the major difference between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong
Nov 21 '05 #1
16 10993
Nak
Hi there,

It's all a matter of object orientation. Look up "Object Orientated
Programming" on google or something like that, or maybe get yourself an
in-depth book, because it is something rather hard to explain in here. It
would be worth your while :-)

Nick.

" A_PK" <pk***@hotmail. com> wrote in message
news:uR******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I am a VB.net beginner, I do not know what are the major difference
between Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong

Nov 21 '05 #2
Hello,
Module in vb.net has everything of a "shared" nature. Once delared it'll be
there throughout the lifetime and instanciated at the start of the
application. This kindof approach introduces too many global variables, which
is not good and as the program grows you'll have a lot of variabes which
belong to the whole program and you kind of kill the concept of
encapsulation, etc,. Use of classes is however an ideal approach where you
think before daclarating and have association-ship as to what variable
belongs to which class and is there for what purpose. You should avoid using
modules, i think they are there only for compatibility with older versions of
VB.
hope that helps.
Abubakar.
http://joehacker.blogspot.com
"A_PK" wrote:
Hi,

I am a VB.net beginner, I do not know what are the major difference between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong

Nov 21 '05 #3
Nak
Hi Abubakar,

Modules are not for legacy compatability. There will allways be the
need for modules, and it's certainly not bad programming practice to take
advantage of them. They are great for storing utility methods or global
constants for example. Some people *like* to use classes with shared
members to achieve the same effect but this is neither here nor there.

They are fit for 2 completely different purposes and shouldn't be
compared as such, Classes are for object orientated approaches, modules
aren't.

Nick.

"Abubakar" <Ab******@discu ssions.microsof t.com> wrote in message
news:92******** *************** ***********@mic rosoft.com...
Hello,
Module in vb.net has everything of a "shared" nature. Once delared it'll
be
there throughout the lifetime and instanciated at the start of the
application. This kindof approach introduces too many global variables,
which
is not good and as the program grows you'll have a lot of variabes which
belong to the whole program and you kind of kill the concept of
encapsulation, etc,. Use of classes is however an ideal approach where you
think before daclarating and have association-ship as to what variable
belongs to which class and is there for what purpose. You should avoid
using
modules, i think they are there only for compatibility with older versions
of
VB.
hope that helps.
Abubakar.
http://joehacker.blogspot.com
"A_PK" wrote:
Hi,

I am a VB.net beginner, I do not know what are the major difference
between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong

Nov 21 '05 #4
A module is equivalent to a Friend, NotInheritable class with shared
properties and methods (and a private constructor to prevent
instantiation).

Nov 21 '05 #5
Nak
Hi Abubakar,

Please don't think that object orientated programming is the *only* way.
Your whole program does not need to be created in this manor. I regularly
use Modules to store global variables, constants and helper methods, I find
this very efficient. If I need a helper method associated to a single class
then I write it in-line as a shared method, but otherwise it isn't
necessary.

"object-orientation is the ultimate goal", nope, a *working* application
that you find easy to maintain is the ultimate goal!

Programming methodologies will always change, but modular and object
orientate approaches are two ways of programming that will always remain; as
they are quite closely linked. VB.NET is just as object orientated as C++,
and at the end of the day C does not exclude "modules" or "includes", it
uses them in tandem. I do see what your trying to say, but I just believe
that maybe you have been blinded by the OOP approach, use both as
appropriate!

Nick.

"Abubakar" <Ab******@discu ssions.microsof t.com> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
Hello Nak,
object-orientation is the ultimate goal. Look at the design of vb.net as
compared to vb6 and before: "everything inside a class". And I was saying
that also because if you see the internal implementation of the modules in
vb.net ie at the IL level, you'll see that its nothing but a class with
shared fields and methods. You can still go for non-object oriented
approach
but changing your approach and thinking in object-oriented ways will
always
help you if you havnt done that before.

Hope that helps.
Abubakar.
http://joehacker.blogspot.com

"Nak" wrote:
Hi Abubakar,

Modules are not for legacy compatability. There will allways be the
need for modules, and it's certainly not bad programming practice to take
advantage of them. They are great for storing utility methods or global
constants for example. Some people *like* to use classes with shared
members to achieve the same effect but this is neither here nor there.

They are fit for 2 completely different purposes and shouldn't be
compared as such, Classes are for object orientated approaches, modules
aren't.

Nick.

"Abubakar" <Ab******@discu ssions.microsof t.com> wrote in message
news:92******** *************** ***********@mic rosoft.com...
> Hello,
> Module in vb.net has everything of a "shared" nature. Once delared
> it'll
> be
> there throughout the lifetime and instanciated at the start of the
> application. This kindof approach introduces too many global variables,
> which
> is not good and as the program grows you'll have a lot of variabes
> which
> belong to the whole program and you kind of kill the concept of
> encapsulation, etc,. Use of classes is however an ideal approach where
> you
> think before daclarating and have association-ship as to what variable
> belongs to which class and is there for what purpose. You should avoid
> using
> modules, i think they are there only for compatibility with older
> versions
> of
> VB.
> hope that helps.
> Abubakar.
> http://joehacker.blogspot.com
>
>
> "A_PK" wrote:
>
>> Hi,
>>
>> I am a VB.net beginner, I do not know what are the major difference
>> between
>> Module vs Class.
>>
>> Could someone guide me when is the best situation to use Module or
>> Class.
>>
>> I have no idea when should I use module or class, because no matter i
>> use
>> module or class, i always could get the results that are what i want.
>> but
>> just the declare and calling method is a bit different.
>>
>> Regards
>> Chong
>>
>>
>>


Nov 21 '05 #6
Nak
Hi "dotnetnewb ie",
Anything that requires more than one instance - think Class.
This is correct, but he possibly does not understand what an instance is
as he has no idea what object orientation is.
If you want to share a set of functions/subs and properties use a module - so long as you don't require multiple instances of the same thing (or object).

Yup, that couldn't be more close to the truth also, are you sure your a
newbie?
OO purists will always say (perhaps) think Class.
That's so true, I read something not so long ago which slagged off OOP
programming over some kind of "table" approach to programming, I can't
remember the article because I do the same thing myself, I'm OOP all over.
But you still have to utilize both classes and modules as necessary.
You should read up on Classes and OOP though.


Well said :-) It's more than we can explain in a thread, unless of
course some of us teach? But still, I have many huge books on OOP, I
wouldn't fancy explaining it! :-)

Nick.
Nov 21 '05 #7
Hello Nak,
object-orientation is the ultimate goal. Look at the design of vb.net as
compared to vb6 and before: "everything inside a class". And I was saying
that also because if you see the internal implementation of the modules in
vb.net ie at the IL level, you'll see that its nothing but a class with
shared fields and methods. You can still go for non-object oriented approach
but changing your approach and thinking in object-oriented ways will always
help you if you havnt done that before.

Hope that helps.
Abubakar.
http://joehacker.blogspot.com

"Nak" wrote:
Hi Abubakar,

Modules are not for legacy compatability. There will allways be the
need for modules, and it's certainly not bad programming practice to take
advantage of them. They are great for storing utility methods or global
constants for example. Some people *like* to use classes with shared
members to achieve the same effect but this is neither here nor there.

They are fit for 2 completely different purposes and shouldn't be
compared as such, Classes are for object orientated approaches, modules
aren't.

Nick.

"Abubakar" <Ab******@discu ssions.microsof t.com> wrote in message
news:92******** *************** ***********@mic rosoft.com...
Hello,
Module in vb.net has everything of a "shared" nature. Once delared it'll
be
there throughout the lifetime and instanciated at the start of the
application. This kindof approach introduces too many global variables,
which
is not good and as the program grows you'll have a lot of variabes which
belong to the whole program and you kind of kill the concept of
encapsulation, etc,. Use of classes is however an ideal approach where you
think before daclarating and have association-ship as to what variable
belongs to which class and is there for what purpose. You should avoid
using
modules, i think they are there only for compatibility with older versions
of
VB.
hope that helps.
Abubakar.
http://joehacker.blogspot.com
"A_PK" wrote:
Hi,

I am a VB.net beginner, I do not know what are the major difference
between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong


Nov 21 '05 #8
Very loosely speaking:

Anything that requires more than one instance - think Class.

If you want to share a set of functions/subs and properties use a module -
so long as you don't require multiple instances of the same thing (or object).

OO purists will always say (perhaps) think Class.

You should read up on Classes and OOP though.

"A_PK" wrote:
Hi,

I am a VB.net beginner, I do not know what are the major difference between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong

Nov 21 '05 #9
Hello Nak,
object-orientation is the ultimate goal. Look at the design of vb.net as
compared to vb6 and before: "everything inside a class". And I was saying
that also because if you see the internal implementation of the modules in
vb.net ie at the IL level, you'll see that its nothing but a class with
shared fields and methods. You can still go for non-object oriented approach
but changing your approach and thinking in object-oriented ways will always
help you if you havnt done that before.

Hope that helps.
Abubakar.
http://joehacker.blogspot.com

"Nak" wrote:
Hi Abubakar,

Modules are not for legacy compatability. There will allways be the
need for modules, and it's certainly not bad programming practice to take
advantage of them. They are great for storing utility methods or global
constants for example. Some people *like* to use classes with shared
members to achieve the same effect but this is neither here nor there.

They are fit for 2 completely different purposes and shouldn't be
compared as such, Classes are for object orientated approaches, modules
aren't.

Nick.

"Abubakar" <Ab******@discu ssions.microsof t.com> wrote in message
news:92******** *************** ***********@mic rosoft.com...
Hello,
Module in vb.net has everything of a "shared" nature. Once delared it'll
be
there throughout the lifetime and instanciated at the start of the
application. This kindof approach introduces too many global variables,
which
is not good and as the program grows you'll have a lot of variabes which
belong to the whole program and you kind of kill the concept of
encapsulation, etc,. Use of classes is however an ideal approach where you
think before daclarating and have association-ship as to what variable
belongs to which class and is there for what purpose. You should avoid
using
modules, i think they are there only for compatibility with older versions
of
VB.
hope that helps.
Abubakar.
http://joehacker.blogspot.com
"A_PK" wrote:
Hi,

I am a VB.net beginner, I do not know what are the major difference
between
Module vs Class.

Could someone guide me when is the best situation to use Module or Class.

I have no idea when should I use module or class, because no matter i use
module or class, i always could get the results that are what i want. but
just the declare and calling method is a bit different.

Regards
Chong


Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3868
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, char*buf); Users will get a Numeric Array object and can change its values (and actually change the underlying C array).
5
2020
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
4
2759
by: Edvard Majakari | last post by:
Greetings, fellow Pythonistas! I'm about to create three modules. As an avid TDD fan I'd like to create typical 'use-cases' for each of these modules. One of them is rather large, and I wondered if it would be easy enough to create a code skeleton out of unit test module. Consider the following, though contrived, unit test code snippet: ==========================================================================
2
2008
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first module (given an instance of the first class) without importing it. Example of what I'm looking for: <<<file spam.py>>> class Spam(object):
25
7755
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i have quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html
10
5497
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in advance
9
2360
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
32
5830
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many classes in a Python module/file. What is the motivation behind it, would it be a bad idea to have a guideline in your project that promotes a one class per file structure (assuming most of the programmers a background similar to mine)?
6
4032
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new types of objects (classes) can only be defined in Class modules.
13
2703
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a module does the same as a class but cannot herite or be herited. 1)Is that right? 2) So i guess this module does exactly the same as the class?
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.