Ver Mensaje Individual
  #8 (permalink)  
Antiguo 28/12/2009, 13:45
Avatar de Myakire
Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
Respuesta: Constructor de clase en ASP

Solo para futuras referencias, antes de revivir un tema antiguo verifica que lo vas a hacer con información que ayude a resolver el problema original, en este caso no se da esa condición, por lo que el tema debiera ser cerrado. Lo ideal seria abrir un tema propio con tu duda en particular e incluyendo la liga a este o a los temas que quieras utilizar como referencia.

Aunque solo por que la referencia estaba a la mano, te colocare lo que dice la MSDN al respecto:

Cita:
Parameterized Constructors
You're probably aware that support for object initialization in earlier versions of Visual Basic has been very limited. In Visual Basic 6.0, for example, your only means for controlling object initialization is to add a custom Class_Initialize method to your class. Let's quickly review what happens when you do this.
When you supply a custom implementation of Class_Initialize, the Visual Basic runtime is guaranteed to call this method whenever a client creates an object from your class. However, this style of initialization isn't very flexible because the Class_Initialize method cannot take parameters. Since the Class_Initialize method cannot take parameters, there's no way for the client (that is, the object creator) to pass instance-specific data when creating an object. Therefore, the only thing that can be initialized inside Class_Initialize are data that have the same values for every instance of the class.
Many experienced developers using Visual Basic found that the best way to work around the limitations of Class_Initialize was to add a public method designed exclusively for object initialization. For example, you can add a public method named Init to your class and give it the parameters that are necessary to properly initialize an object. When a class includes a public method for initialization, the client has the responsibility of calling this method after creating a new object. Here's an example of a class that is based on this type of design approach.
Class Person
Private name As String
Private age As Integer
Public Sub Init(n As String, a As Integer)
name = n
age = a
End Sub
End Class

Given a class definition such as this, the client should call the Init method immediately after creating the object. Here's an example of what the client code usually looks like.
Dim obj As New Person
obj.Init("Bob", 32)
' now access other members
A design technique such as the one I've just shown is often called two-phase construction. The object is created in phase one and it's initialized in phase two. It's important to keep in mind that designs that use two-phase construction place a responsibility on the programmer writing client-side code against the class. It is incorrect for client code to access any other member defined inside the class before calling Init. If the client-side programmer forgets to call Init, the class code will probably not behave as the author intended. It's unfortunate, but there's nothing you can do as a class author to make the compiler force a client-side programmer to call the Init method.
The introduction of parameterized constructors provides a much more elegant solution to the problem that I've just described. Let's take a look at how to redesign the Person class using this new feature.
http://msdn.microsoft.com/en-us/magazine/cc301735.aspx

Saludos