Creanlo o no, no he podido encontrar en ningun lado la sintaxis para crear un bendito constructor de clase en ASP (el viejito)
mi clase se llama Computadora
necesito saber como declarar el constructor para inicializar variables.
Gracias!!
| |||
Constructor de clase en ASP Creanlo o no, no he podido encontrar en ningun lado la sintaxis para crear un bendito constructor de clase en ASP (el viejito) mi clase se llama Computadora necesito saber como declarar el constructor para inicializar variables. Gracias!! |
| |||
Re: Constructor de clase en ASP hola: tambien me vi en esas circunstancias hace un tiempo atras. no encontre la forma de declarar un constructor, hasta donde yo se no se puede, lo que hice fue declarar un procedimiento (Inicializar) en la clase, donde inicializo las variables que necesito. ej.: set ObjComputador = new Computador ObjComputador.Inicializar fue la unica solucion que encontre en el momento. ojala te sirva de algo. seguire buscando como declarar un constructor ya que tambien lo necesito. |
| ||||
Re: Constructor de clase en ASP Existe el evento Initialize de la clase en VBS, que podría ser visto como un constructor: http://msdn.microsoft.com/library/de...9b1146d97f.asp
__________________ "El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera." -- Ernest Hemingway |
| ||||
Re: Constructor de clase en ASP Funcionan como un constructor y destructor normalitos .... es decir, no tienes que invocar en el objeto instanciado a esos métodos, ellos se lanzan al momento del instanciamiento y su destrucción |
| |||
Respuesta: Constructor de clase en ASP Buenas. Tengo una duda en referencia al Class_Initialize. Necesito que cuando se haga el llamado al contructor de la clase, se le pasen parámetros a la misma, para poder inicializar unos atributos de dicha clase, por ejemplo: index.asp
Código:
... Set prueba = New Pepito("hola", "adios") ... pepito.asp
Código:
Class Pepito ' Atributos de la clase '-------------------------------------- Private variable1 Private variable2 ' Constructor '------------------- Private Sub Class_Initialize(ByVal str_variable1, ByVal str_variable2) variable1 = str_variable1 variable2 = str_variable2 End Sub End Class Lo he probado y me lanza el siguiente error: La inicialización o finalización de la clase no tiene argumentos Con lo cual creo que no es posible pasarle parámetros al contructor, entonces no se si me pueden aconsejar en algo, ya que lo unico que se me ocurre es crear un metodo propio de la clase en la cual se inicialicen los valores, pero esto no lo veo muy eficiente que digamos ![]() Muchas gracias de antemano y un saludo |
| ||||
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: http://msdn.microsoft.com/en-us/magazine/cc301735.aspxParameterized 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. Saludos |