Re: hiding an interface (VB6)
From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 04/30/04
- Previous message: alpine: "Re: Interfaces"
- In reply to: Mark Meyers: "Re: hiding an interface (VB6)"
- Next in thread: Mark Meyers: "Re: hiding an interface (VB6)"
- Reply: Mark Meyers: "Re: hiding an interface (VB6)"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 30 Apr 2004 14:55:00 -0600
>I didn't notice a check in your Init() to see if it had already been
>initialized. Was that intentional?
What do you call this? ;-)
> If Not bInitialized Then
HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
On Fri, 30 Apr 2004 12:48:43 -0400, "Mark Meyers"
<mmeyers[at]hydromilling.com> wrote:
>Right - these are good ideas (both posts), and they look much like the ideas
>I've come up with.
>
>I didn't notice a check in your Init() to see if it had already been
>initialized. Was that intentional?
>
>I have also created a smaller object from the original, and am now passing
>the smaller one to callers. The bigger object remains contained, with all
>of it's entrypoints private.
>
>Something like this:
>' class BigObject
>
>private x as integer, y as integer
>
>' properties coded to read/write the x and y
>
>public function CreateSmallObject() _
>as SmallObject
> dim sm as SmallObject
> set sm = new SmallObject
> sm.Init(x,y)
> set CreateSmallObject = sm
>end sub
>
>' class SmallObject
>
>private bInit as boolean ' true when init has been done
>private x as integer, y as integer
>
>' properties coded to read the x and y (not write)
>
>public function Init(newx as integer, newy as integer)
> if bInit then
> msgbox "You goofed"
> Init = False
> exit function
> end if
> x = newx
> y = newy
> bInit = True
>end function
>
>- Mark
>
>"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
>news:mjr490leuk82igqhanpcmi4ufiocekfp76@4ax.com...
>>
>> If you are content with being able to set the values contained within
>> the object when you initialize it, you could do something like the
>> following that would only allow the contained values to be set on the
>> first call to it's Init function....
>>
>> ' class objcet....
>> Option Explicit
>>
>> Private m_sMemberData1 As String
>> Private m_nMemberData2 As Long
>> Private m_bMemberData3 As Boolean
>>
>> Public Function Init(ByVal sData1 As String, ByVal nData2 As Long,
>> ByVal bData3 As Boolean) As Boolean
>>
>> Static bInitialized As Boolean
>>
>> If Not bInitialized Then
>> bInitialized = True
>>
>> m_sMemberData1 = sData1
>> m_nMemberData2 = nData2
>> m_bMemberData3 = nData3
>> End If
>>
>> End Function
>>
>> Public Property Get Data1() As String
>> Data1 = m_sMemberData1
>> End Property
>>
>> Public Property Get Data2() As Long
>> Data2 = m_nMemberData2
>> End Property
>>
>> Public Property Get Data3() As Boolean
>> Data3 = m_bMemberData3
>> End Property
>>
>>
>> Another option would be to have your object implement an interface
>> with "read only" access to the data contained within. You could then
>> pass a reference to the read only interface to those who should only
>> have read only access.
>>
>> HTH,
>> Bryan
>
- Previous message: alpine: "Re: Interfaces"
- In reply to: Mark Meyers: "Re: hiding an interface (VB6)"
- Next in thread: Mark Meyers: "Re: hiding an interface (VB6)"
- Reply: Mark Meyers: "Re: hiding an interface (VB6)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|