Re: Sharing an instance of an object across classes



Beth,

Don't mix up OO and OOP, OOP is to be able to use small memory with tons of classes.

At the moment I am busy with doing some corrections on a VB6 program that was made by others 8 years ago. It is nicely done and still it is a hell to do as you are used to .Net programming languages.

In OOP you create small methods which can be seen on them self and as you use them more by making classes of them.
Try it, add the end you will think, how could I ever do it on the classic way.

I was in past a devoted follower of Dijkstra, but that was in the time that there were no PC's, mobiles, Internet and more of that stuff.

Cor


"Beth" <Beth@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:FD41869A-4125-4710-831A-CCD26627E2F7@xxxxxxxxxxxxxxxx
Hi, Cor.
Thanks for your response.

I'm using a VB6 naming convention, yes, but not modules because you can't
instantiate one or more instances of a module, can't listen for events, and
can't associate the actions on a data structure with the data structure
itself. Not to mention all the other OO stuff you can't do.

I can see why people are religious about using OO methods instead of
structured programming, but I haven't found a lot of instructor-led classes
focusing on those concepts outside of UML. I had the material presented in
college, of course, but I don't remember that. Yes, there's tons of books and
info online, but I learn better from asking someone questions after they've
presented something and I need to make sure I understand them.

If you're aware of a 'OO for VB6-to-.NET programmers' forum somewhere,
please let me know. Naming conventions I can change.

I'm not even sure if Microsoft has an OO forum somewhere, for those of us
trying to learn more.

Well, anyways, thanks for replying.

-Beth

"Cor Ligthert[MVP]" wrote:

Beth,

It sounds for me a bad idea to use VB6 style code where OOP can be used.

But as you want that, simple use modules instead of classes.

jmo

Cor

"Beth" <Beth@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8D42B0F4-6D5C-4A5F-B32A-330F97A7B8C0@xxxxxxxxxxxxxxxx
> Hello.
>
> I'm trying to find another way to share an instance of an object with
> other
> classes.
>
> I started by passing the instance to the other class's constructor, > like
> this:
>
> Friend Class clsData
> Private m_objSQLClient As clsSQLClient
> Private m_objUsers As clsUsers
> Private m_sConnect As String
>
> Friend Sub connect(ByVal bDebuggerAttached As Boolean)
> Dim sServer As String
> Dim sDB As String
>
> If bDebuggerAttached Then
> sServer = "test"
> Else
> sServer = "prod"
> End If
> sDB = "appdb"
>
> m_sConnect = "Data Source=" & sServer & ";Database=" & sDB & > ";Integrated
> Security=true"
> m_sConnect = m_sConnect & ";Application Name = " &
> My.Application.Info.AssemblyName
>
> m_objSQLClient = New clsSQLClient
> m_objSQLClient.connect(m_sConnect)
>
> m_objUsers = New clsUsers(m_objSQLClient)
> End Sub
> End Class
>
> Friend Class clsUsers
> Private m_objSQLClient As clsSQLClient
> Private m_dtUser As DataTable
>
> Friend Sub New(ByVal objSQLClient As clsSQLClient)
> m_objSQLClient = objSQLClient
> End Sub
>
> Friend Function markEntry() As String
> Try
> m_dtUser = m_objSQLClient.tableForEdit("users")
>
> This works, but I don't like it. I want clsUsers to refer directly to > the
> instance variable in clsData instead of passing a parameter.
>
> Then I saw an example using inheritance that I liked, so I added:
>
> Protected Friend Function sqlClient() As clsSQLClient
> Return m_objSQLClient
> End Function
>
> To clsData and I deleted the constructor in clsUsers and changed the > code
> to:
>
> Friend Class clsUsers
> Inherits clsData
> Private m_dtUser As DataTable
>
> Friend Function markEntry() As String
> Try
> m_dtUser = MyBase.sqlClient.tableForEdit("users")
>
> but it doesn't work- it raises an exception when clsUsers.markEntry
> references mybase.sqlClient.
>
> Is there another way I can do this, or do I need to stick with passing > the
> object instance as a parameter?
>
> Thanks for any help,
>
> -Beth



.



Relevant Pages