5
\$\begingroup\$

I have to create a website in Classic ASP, and I really want to do a clean design so I will try to put everything in Classes and Models to emulate the ViewModel Pattern.

So can you tell me if this approach of creating objects is good because I will use it everywhere

Class User
    Public Name
    Public Adress
    Public Title
    Public Text 
    Public Rights 'ArrayList of Right objects

    Private Sub Class_Initialize()
       Initialize
    End Sub

    Private Sub Class_Terminate()
       Dispose
    End Sub

   Private Sub Initialize()
       Name    = ""
       Adress  = ""
       Title   = ""
       Text    = ""
       Set Rights = Server.CreateObject("System.Collections.ArrayList") ' Arraylist .net
   End Sub

   Private Sub Dispose()      
   End Sub

End Class

Class Right

    Public Name

    Private Sub Class_Initialize()
        Initialize
    End Sub

   Private Sub Class_Terminate()
       Dispose
   End Sub

   Private Sub Initialize()
       Name    = ""
   End Sub

   Private Sub Dispose()      
   End Sub
End Class

And then I do this for instantiating objects :

Dim myUser 
Set myUser = New User

'Do some work

Set myUser = nothing 'Dispose the object 

Any idea, suggestion or correction is welcome.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ I don't see any problems with the supplied code. \$\endgroup\$ Commented Sep 4, 2012 at 5:10
  • \$\begingroup\$ it's missing something.....Semicolons....jk \$\endgroup\$
    – Malachi
    Commented Nov 19, 2013 at 15:17

2 Answers 2

2
\$\begingroup\$

I am not a big VB person, but I would think that if you give your class a Dispose method you should use it rather than setting it to nothing, I know this is kind of the same thing, but if you aren't going to use the Method don't create the method, it's extra stuff. if you are going to use it in the future, comment to that effect.

'This Method is for future development
Private Sub Dispose()
End Sub

OR

'TODO: Implement!
Private Sub Dispose()
End Sub

my comment syntax is probably off a little bit.

\$\endgroup\$
4
  • \$\begingroup\$ Yeah, like '''TODO: Crea Dispose Method. should read 'TODO: Implement!! \$\endgroup\$ Commented Nov 19, 2013 at 15:28
  • \$\begingroup\$ I was trying to do the xml comment or whatever it is. so it alerts you that there is something left to do \$\endgroup\$
    – Malachi
    Commented Nov 19, 2013 at 15:31
  • \$\begingroup\$ I don't think there's such a fancypants thing in VBScript :) \$\endgroup\$ Commented Nov 19, 2013 at 15:37
  • \$\begingroup\$ well I was thinking ASP.NET....lol \$\endgroup\$
    – Malachi
    Commented Nov 19, 2013 at 15:45
1
\$\begingroup\$

That's very nice & tidy, if you write all your code as cleanly, I want to debug your code!!

That said I might be wrong, but I don't think there's a Dispose pattern in VBScript (that's not .net!), but I see what you're trying to accomplish and it's excellent - use that method to set all your resources to Nothing.

The only thing I'd warmly recommend, is to use the vbNullString constant instead of "" - vbNullString takes 0 bytes of memory, which isn't the case for "".

\$\endgroup\$
1
  • \$\begingroup\$ I changed the Tag from vbscript to vb.net because of the wording of the question I thought that he was probably writing in vb.net and not vbscript \$\endgroup\$
    – Malachi
    Commented Nov 19, 2013 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.