类中的层次结构 [英] Hierarchy inside a class

查看:74
本文介绍了类中的层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在类中创建一个对象层次?

这是一段伪代码



类Database1



    Dim xyz As SqlClient.SqlConnection = ...



    Singleton Schema1
$
    

       共享函数getTable123()as DataTable

            :

            

            

我希望这样做:



Dim db1 As New Database1            

Dim db2 As New Database2  '相同的数据库,其他连接

      :
$
dt1 = db1.Schema1.getTable123()

dt2 = db1.Schema1.getTable456()
$


对于这个函数,getTable123和getTable456需要在Database1的正确实例中访问sqlconnection xyz。 
$


我不想实现Schema1,这就是我使用的原因单例。



用Schema1替换类Schema1在这里工作但我需要公开结构(我不想要)。



我想要的是什么?是这样,怎么样?

解决方案

单身人士,在这种情况下是什么?


在Windows的情况下我没有看到这种可能性(它是一个Unix大型机概念)


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


请注意,如果您在互联网上搜索,您会发现很多样本单身,但主要是它不是服务器上而是客户端上的程序的单个实例。


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?

解决方案

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. 


这篇关于类中的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆