English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Normally inside a Class, we have some private variables because of the need for encapsulation. But does encapsulation also apply to Module?

Should I write:

Module Module1

Private p As Person

Sub Main()
...
End Sub

End Module

Or I should write:

Module Module1

Dim p As Person

Sub Main()
...
End Sub

End Module

2007-06-03 23:41:59 · 3 answers · asked by Hello World 1 in Computers & Internet Programming & Design

Thank you very much for your help.

2007-06-03 23:42:28 · update #1

3 answers

Encapsulation also applies to a module. The major difference between the Class and Module is that a class object may be duplicated many times and cuctoms events can be defined.

You can define Public and Private variable, properties and methods in a module just as in a class.


I preferr to define module level variables with either Public or Private and NEVER Dim. I reserve DIM for use exclusively within Subroutines and Functions.

Most variables I declare at module level are Private unless there is some rare need for a global variable. I also preface each module variable with either m_ or g_ to indicate it is either Private or Public.

Rather than define global variables you can create Public properties.

Private m_P as Person
Public g_P as Person

Public Property P as Person

get
p = m_P
end get

set P (Value as Person)

m_P = value
end set
end property



Also I don't like to define global and public variables/properties with single character names. It is to easy to mistype and create a logic error rather than a syntax error. Syntax error are easy to find and won't compile unlike a logic error. So I might change the above property from P as Person to somthing like myPerson.

2007-06-04 02:07:06 · answer #1 · answered by MarkG 7 · 0 0

Inside a module, I am pretty sure that variables are private by default. Meaning that the two that you wrote are the same. Unless you say public p as person, then p won't be accessible outside the module.

2007-06-04 06:46:02 · answer #2 · answered by Anonymous · 0 0

http://www.hacking-passion.com

2007-06-04 06:46:10 · answer #3 · answered by Muhammad 1 · 0 0

fedest.com, questions and answers