none
Hierarchy inside a class RRS feed

  • Question

  • Is it possible to create an object hierachy inside a class?
    Here is a piece of pseudocode

    Class Database1

        Dim xyz As SqlClient.SqlConnection = ...

        Singleton Schema1
        
            Shared Function getTable123() as DataTable
                :
                
                
    I wish to do things like this:

    Dim db1 As New Database1            
    Dim db2 As New Database2  'Same database, other connection
          :
    dt1 = db1.Schema1.getTable123()
    dt2 = db1.Schema1.getTable456()

    For this functions getTable123 and getTable456 need to access the sqlconnection xyz in the proper instance of Database1. 

    I do not want to instanciate Schema1, thats why I used a singleton.

    Replacing Class Schema1 with Structure Schema1 works here but then I need to expose the structure as well (which I don't want).

    Is what I want at all possible? Is so, How?
    Wednesday, November 15, 2017 12:12 PM

All replies

  • A singleton, what is that in this case ?

    I don't see a possibility for this in the case of Windows (it is a Unix mainframe concept)

    https://en.wikipedia.org/wiki/Singleton_pattern

    Be aware that if you search on Internet you find many samples for a singleton, however mostly it is a single instance of a program not on the server but on the client. 


    Success
    Cor

    Wednesday, November 15, 2017 12:43 PM
  • Is it possible to create an object hierachy inside a class?

    That's a very open-ended question but as stated:

    Public Class ExampleA
        Public Property Something As ExampleB
    End Class
    
    
    
    
    
    Public Class ExampleB
        Public Property Something As ExampleC
    End Class
    
    
    
    
    
    Public Class ExampleC
        Public Property Something As String
    End Class

    That one has nothing to do with the Singleton pattern but it's a hierarchy.

    ***** EDIT *****

    In addition, don't forget nested classes:

    Public Class MyMainClass
        Public Class MySubMainClass
            Public Class MySubSubMainClass
                ' Nesting is also hierarchical
            End Class
        End Class
    End Class


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Wednesday, November 15, 2017 1:17 PM
  • Replacing Class Schema1 with Structure Schema1 works here but then I need to expose the structure as well (which I don't want).

    How can you do

        dt1 = db1.Schema1.getTable123()

    if Schema1 is not exposed?  I think that Schema1 is something other than the one function you have listed, and that there are parts of it that you won't want to expose. How you would do that depends on the detail of what that object is.

    Wednesday, November 15, 2017 8:46 PM