473,567 Members | 2,898 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 10963
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
3848
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...
5
2010
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
2741
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
1998
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
7733
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...
10
5476
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
2337
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
5783
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...
6
4016
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
2680
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
7590
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...
0
7905
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. ...
0
7960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6272
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...
1
5488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
930
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...

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.