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
16 10994
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
> You should avoid using modules, i think they are there only for compatibility with older versions
of VB.
Then why are there so many Modules in the framework? Examples include...
System.Math
System.IO.File
One should use a module when there is no "object" associated with the
functions you are writing.
Too often people become enamored with "Object Orientated" and forget that
objects are not everything, they are just another tool. And like all tools,
there are times when they should not be used.
Off the top of my head, VB's FileSystemObjec t. You have to create an
instance of the FSO before using it, even though you will never need more
than one FSO. In fact, you could create a hundred of them and they would all
be exactly the same.
I cringe whenever I someone mentions a "singleton" pattern. In all most all
cases, your so-called singleton is really just a global variable that people
pretend is a class.
--
Jonathan Allen
"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
> 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.
True, but it is easier to say "Math is a Module" than "Math is a class that
isn't really a class because it has no constructors and all its members are
shared".
--
Jonathan Allen
"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 > > >
Hi Jonathan,
More than likely you will cringe when you see this reply from me, but it
isn't bad; in context, so there is no need. Anyway... One should use a module when there is no "object" associated with the functions you are writing.
Exactly, everything has a purpose and there is no right or wrong way
about programming. Some techniques prove much better for certain uses than
OOP does. It all depends on what you are trying to achieve.
Too often people become enamored with "Object Orientated" and forget that objects are not everything, they are just another tool. And like all tools, there are times when they should not be used.
ACK.
Off the top of my head, VB's FileSystemObjec t. You have to create an instance of the FSO before using it, even though you will never need more than one FSO. In fact, you could create a hundred of them and they would all be exactly the same.
I'm a little OT, but I started using JAVA before I used the beta of
VB.NET and I am rather surprised as to how close the JAVA "run-time" is to
the .NET Framework, the way the class hierarchy is laid out is almost
identical in certain circumstances. I'm sure Microsoft had a lot to say but
it just goes to show how much the CLR is needed! I crated my own file
objects for VB6 that are almost identical to VB.NET, it's weird how an
inferior "desktop" language has come up with far better ideas!
I cringe whenever I someone mentions a "singleton" pattern. In all most all cases, your so-called singleton is really just a global variable that people pretend is a class.
But even they have their uses. For example, if you are sharing objects
between instances then sometimes a singleton is essential! For example, if
I create a singleton object for my application it would make it much easier
for me to maintain only 1 running instance. This appears to be something
that is really overlooked by people that utilize command line arguments, a
singleton is essential! What's the point in having an MDI application with
multiple instances?
Nick.
My app-o-log-gies, I have just observed that you are not the Jonathan that I
thought you were! So Ignore the first paragraph!
"Nak" <a@a.com> wrote in message
news:eN******** ******@TK2MSFTN GP15.phx.gbl... Hi Jonathan,
More than likely you will cringe when you see this reply from me, but it isn't bad; in context, so there is no need. Anyway...
One should use a module when there is no "object" associated with the functions you are writing.
Exactly, everything has a purpose and there is no right or wrong way about programming. Some techniques prove much better for certain uses than OOP does. It all depends on what you are trying to achieve.
Too often people become enamored with "Object Orientated" and forget that objects are not everything, they are just another tool. And like all tools, there are times when they should not be used.
ACK.
Off the top of my head, VB's FileSystemObjec t. You have to create an instance of the FSO before using it, even though you will never need more than one FSO. In fact, you could create a hundred of them and they would all be exactly the same.
I'm a little OT, but I started using JAVA before I used the beta of VB.NET and I am rather surprised as to how close the JAVA "run-time" is to the .NET Framework, the way the class hierarchy is laid out is almost identical in certain circumstances. I'm sure Microsoft had a lot to say but it just goes to show how much the CLR is needed! I crated my own file objects for VB6 that are almost identical to VB.NET, it's weird how an inferior "desktop" language has come up with far better ideas!
I cringe whenever I someone mentions a "singleton" pattern. In all most all cases, your so-called singleton is really just a global variable that people pretend is a class.
But even they have their uses. For example, if you are sharing objects between instances then sometimes a singleton is essential! For example, if I create a singleton object for my application it would make it much easier for me to maintain only 1 running instance. This appears to be something that is really overlooked by people that utilize command line arguments, a singleton is essential! What's the point in having an MDI application with multiple instances?
Nick.
> But even they have their uses. For example, if you are sharing
objects between instances then sometimes a singleton is essential!
Well, there are cases when you want a pointer to either "this single
instance" or "that single instance". For example, different engineer for
calculating geographical distance. (Geo-distance is a lot harder than one
might suppose.)
For example, if I create a singleton object for my application it would make it much
easier for me to maintain only 1 running instance.
Bad example. Each instance of the application would have an instance of the
singleton.
This appears to be something that is really overlooked by people that utilize command line arguments, a singleton is essential!
I've never used one, I just use a module.
What's the point in having an MDI application with multiple instances?
True.But if for some reason you later decide you really do want multiple
instances of the main window, you'll be glad you didn't use the singleton's
global.
*************** **
Accidental Classes OR How I just screwed up.
If you find that your class has this pattern, you screwed up...
1. There is a shared array.
2. All created objects are stored in the array.
3. There are lots of shared methods that work on said array.
I didn't notice at the time, but I had a collection class hidden within my
shared fields/methods. Now that I need two instances of that collection, I
am [insert explicative here].
In this instance, I should have used a real singleton in order to allow me
more flexibility over the long run.
--
Jonathan Allen
"Nak" <a@a.com> wrote in message
news:eN******** ******@TK2MSFTN GP15.phx.gbl... Hi Jonathan,
More than likely you will cringe when you see this reply from me, but
it isn't bad; in context, so there is no need. Anyway...
One should use a module when there is no "object" associated with the functions you are writing. Exactly, everything has a purpose and there is no right or wrong way about programming. Some techniques prove much better for certain uses
than OOP does. It all depends on what you are trying to achieve.
Too often people become enamored with "Object Orientated" and forget
that objects are not everything, they are just another tool. And like all tools, there are times when they should not be used. ACK.
Off the top of my head, VB's FileSystemObjec t. You have to create an instance of the FSO before using it, even though you will never need
more than one FSO. In fact, you could create a hundred of them and they would all be exactly the same.
I'm a little OT, but I started using JAVA before I used the beta of VB.NET and I am rather surprised as to how close the JAVA "run-time" is to the .NET Framework, the way the class hierarchy is laid out is almost identical in certain circumstances. I'm sure Microsoft had a lot to say
but it just goes to show how much the CLR is needed! I crated my own file objects for VB6 that are almost identical to VB.NET, it's weird how an inferior "desktop" language has come up with far better ideas!
I cringe whenever I someone mentions a "singleton" pattern. In all most all cases, your so-called singleton is really just a global variable that people pretend is a class. But even they have their uses. For example, if you are sharing
objects between instances then sometimes a singleton is essential! For example,
if I create a singleton object for my application it would make it much
easier for me to maintain only 1 running instance. This appears to be something that is really overlooked by people that utilize command line arguments, a singleton is essential! What's the point in having an MDI application
with multiple instances?
Nick.
Hi Jonathan, Bad example. Each instance of the application would have an instance of the singleton.
As far as I am aware there is more than one type of singleton. If you
implement a singleton object that uses remoting then you have the perfect
solution, I've been using it now for quite a while and I haven't actually
used anything that's been more reliable or easy to implement. That's after
I got past the initial confusion of remoting.
I've never used one, I just use a module.
They are worth looking into, imagine multiple instances of Adobe
Photoshop, 1 is enough for me that's for sure. But having that quick link
between your instances is great, it saves allot of time and stops you having
to mess around with window messaging and the like.
True.But if for some reason you later decide you really do want multiple instances of the main window, you'll be glad you didn't use the singleton's global.
Well that's where a singleton's flexibility comes in, I'm sure it
wouldn't be difficult to set a maximum number of instances, and when you
launch 1 after the limit has been met; to have the choice of which instance
to send the arguments too.
Accidental Classes OR How I just screwed up.
If you find that your class has this pattern, you screwed up...
1. There is a shared array. 2. All created objects are stored in the array. 3. There are lots of shared methods that work on said array.
I didn't notice at the time, but I had a collection class hidden within my shared fields/methods. Now that I need two instances of that collection, I am [insert explicative here].
In this instance, I should have used a real singleton in order to allow me more flexibility over the long run.
I'm obviously no master of singleton implementation, most of the
information that I found about it was written by an MVP in here, though I
can't remember the exact person, may have been Jay. Anyway, I think the
phrase is "6ugger"! http://www.codeproject.com/dotnet/remotingsingleton.asp
^Check that out :-) With a remoting singleton you could even maintain 1
instance across a network, though I'm sure it wouldn't be without it's
difficulties!
Nick. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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).
|
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
==============
==============
|
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:
==========================================================================
|
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):
|
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
| |
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
|
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)
|
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)?
|
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.
|
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?
|
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...
| |
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,...
|
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...
|
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,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |