Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2009, 03:25 PM
Registered User
 
Join Date: Nov 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default OOP ASP question

I'm working on a class and I'm curious about setting properties values.

I'm just getting started in OOP and I'm using some online examples. I've been able to successfully incorporate 2 main classes into my application.

I'm curious about how to make this work or possibly a different method:

Code:
Public Class Foo
    Private privID
    Private privName
    
    Private Sub Class_Initialize()
        ' granted the pID isn't set yet, but maybe define another method to get it
        ' this was all just flying by the seat of my pants
        Call mGetName
    End Sub
    
    Public Property Get pID
        pID = privID
    End Property
    Public Property Let pID(value)
        privID = value
    End Property
    
    Public Property pName
        pName = privName
    End Property
    
    Private Sub mGetName
        ' some query here WHERE ID = pID
        privName = [query results]
    End Sub
End Class

Dim cFoo, Name
Set cFoo = New Foo
cFoo.pID = (Form/QueryString/Session)
Name = cFoo.pName

<%= cFoo.pName %>
Versus this idea:

Code:
Public Class Foo
    Private privName
    
    Public Property Get pName
        pName = privName
    End Property
    Public Property Let pName(value)
        privName = value
    End Property
    
    Private Function mGetName(value)
        ' some query here WHERE ID = value
        mGetName = [query results]
    End Function
End Class

Dim cFoo, Name
Set cFoo = New Foo
cFoo.pName = cFoo.mGetName(Form/QueryString/Session)

<%= cFoo.pName %>
Any advantage of one technique over the other? I'd imagine there are even other techniques.

Any insight is appreciated.

Last edited by LAYGO; November 10th, 2009 at 03:27 PM..
 
Old November 10th, 2009, 03:32 PM
Registered User
 
Join Date: Nov 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess writing all that out & thinking about it more, the 2nd technique seems much more compact.

The one question I had (that I failed to ask) is how would a method define a property or several properties?

Code:
Public Class Foo
    Property p1
    Property p2
    ....
    Property pN
    
    Private Sub Class_Initialize()
        Call mGetProperties
    End Sub
    
    Private Sub mGetProperties
        ' query to get the data
        p1 = row1,col1
        p2 = row1,col2
        p3 = row1,col3
        .....
        pN = rowN,colX
    End Sub
End Class





Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP Design Prob SiliconFuRy Java Basics 1 April 6th, 2006 03:01 PM
Classes (OOP) in VBScript 6 benr Pro VB 6 12 March 13th, 2006 04:02 PM
OOP design raj_sekhar C++ Programming 1 August 23rd, 2005 11:44 AM
OOP with JavaScript Moharo Javascript 3 September 29th, 2003 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.