草庐IT

DownloadThread

全部标签

python - 在 Python 中的另一个类中定义一个类有什么好处吗?

我在这里谈论的是嵌套类。本质上,我有两个正在建模的类(class)。一个DownloadManager类和一个DownloadThread类。这里明显的OOP概念是组合。但是,组合并不一定意味着嵌套,对吧?我的代码看起来像这样:classDownloadThread:deffoo(self):passclassDownloadManager():def__init__(self):dwld_threads=[]defcreate_new_thread():dwld_threads.append(DownloadThread())但现在我想知道是否存在嵌套更好的情况。比如:classDo

python - 在 Python 中的另一个类中定义一个类有什么好处吗?

我在这里谈论的是嵌套类。本质上,我有两个正在建模的类(class)。一个DownloadManager类和一个DownloadThread类。这里明显的OOP概念是组合。但是,组合并不一定意味着嵌套,对吧?我的代码看起来像这样:classDownloadThread:deffoo(self):passclassDownloadManager():def__init__(self):dwld_threads=[]defcreate_new_thread():dwld_threads.append(DownloadThread())但现在我想知道是否存在嵌套更好的情况。比如:classDo