Module and Class

  • Thread starter Thread starter Laserson
  • Start date Start date
Laserson.

A module is a piece of program directly on the program stack.

An object is a piece of program placed on the managed heap.
(Another place in memory, however more flexible to use).

An object is made by instancing a Class. That means that on the program
stack is an address that tells where the created object is.

If you have read about a shared Class, than that is almost the same as a
Module. The main difference for me is, that a Shared Class gives you more
possibilitie to describe things more nice.

I hope this helps,

Cor
 
Hi! I can't understand what difference between modules and classes in VB.NET

A module is basically a class where all the members are implicitly
Shared and without any constructor so you can't create instances of
it.


Mattias
 
Laserson said:
I can't understand what difference between modules and classes in VB.NET
project?


Classes are used to model /entities/ such as cars, customers, and pets which
can be instantiated multiple times. Modules on the other hand are used to
/group/ functions which belong to each other, but do not form an entity
(file access functions, for example).
 
A module is really just a shorthand for a Friend, NotInheritable class with
only shared members and an implicit private constructor to avoid
instantiation.

The one wrinkle is that VB lets you access the members without qualification.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
:
: A module is really just a shorthand for a Friend, NotInheritable class
: with only shared members and an implicit private constructor to avoid
: instantiation.
:
: The one wrinkle is that VB lets you access the members without
: qualification.


I understood everything except that last comment. What do you mean by that?
Thanx,


Ralf
 
David,
A module is really just a shorthand for a Friend,

It can be Public too.

an implicit private constructor to avoid
instantiation.

Or rather no constructor at all. A private ctor doesn't prevent
instantiation from within the type itself.


Mattias
 
No - if you specify "Public" it still can't be accessed outside of the
project - so for modules "Public" means the same as "Friend".

(Unless Microsoft has changed this for 2005...?)

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
If you have a module named "MyModule" with the method "MyMethod", you can
simply specify "MyMethod" elsewhere in your project - you don't need to have
"MyModule.MyMethod", which you would have to do for a shared method in a
regular class.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
Suspected as much, but wasn't sure. Thanx for the clarification.

Ralf

: If you have a module named "MyModule" with the method "MyMethod", you can
: simply specify "MyMethod" elsewhere in your project - you don't need to
have
: "MyModule.MyMethod", which you would have to do for a shared method in a
: regular class.
: --
: David Anton
: www.tangiblesoftwaresolutions.com
: Instant C#: VB to C# converter
: Instant VB: C# to VB converter
: Instant C++: C# to C++ converter & VB to C++ converter
: Instant J#: VB to J# converter
:
:
:
: "_AnonCoward" wrote:
:
: >
: > : > :
: > : A module is really just a shorthand for a Friend, NotInheritable class
: > : with only shared members and an implicit private constructor to avoid
: > : instantiation.
: > :
: > : The one wrinkle is that VB lets you access the members without
: > : qualification.
: >
: >
: > I understood everything except that last comment. What do you mean by
that?
: > Thanx,
: >
: >
: > Ralf
: > --
: > --
: > ----------------------------------------------------------
: > * ^~^ ^~^ *
: > * _ {~ ~} {~ ~} _ *
: > * /_``>*< >*<''_\ *
: > * (\--_)++) (++(_--/) *
: > ----------------------------------------------------------
: > There are no advanced students in Aikido - there are only
: > competent beginners. There are no advanced techniques -
: > only the correct application of basic principles.
: >
: >
: >
 
No - if you specify "Public" it still can't be accessed outside of the
project - so for modules "Public" means the same as "Friend".

(Unless Microsoft has changed this for 2005...?)


I can use a public module from another assembly in both v7.1 and v8.0.


Mattias
 
Interesting discussion...I learn something everyday. While reading this
string of notes, it came to me that a lot of people on this newsgroup often
recommend using a class instead of a modules Since a module is really a
class without a constructor where public functions, subs, and variables are
shared, why the mindset against modules?
 
Others can outline the other reasons, but personally I don't like the way
that modules hide their special characteristics. This leads programmers to
code by rote without understanding fully what they're doing. I realize that
many VB programmers do know what they are doing when they code a module, but
many don't and anything that encourages ignorance can cause problems down the
road.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
Dennis,
Interesting discussion...I learn something everyday. While reading this
string of notes, it came to me that a lot of people on this newsgroup
often
recommend using a class instead of a modules Since a module is really a
class without a constructor where public functions, subs, and variables
are
shared, why the mindset against modules?
--

For me is it the one as David wrote.
The one wrinkle is that VB lets you access the members without
qualification

If you use modules, than in a large project you don't know where the
variable/object is placed.

It can be in your method, it can be globaly in your own class, it can be in
a module.

The first to are rather quick to find in those cases that you don't use a
module (and don't set the global variables between the methods however
always on the same place). It is in your method or globaly in your class.

If you use a module than you have to search in every module that you use as
well.

I hope that this gives an idea?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top