我在这里谈论的是嵌套类.基本上,我有两个我正在建模的类.DownloadManager类和DownloadThread类.这里显而易见的OOP概念是构图.然而,构图并不一定意味着嵌套,对吧?
我的代码看起来像这样:
class DownloadThread:
def foo(self):
pass
class DownloadManager():
def __init__(self):
dwld_threads = []
def create_new_thread():
dwld_threads.append(DownloadThread())
Run Code Online (Sandbox Code Playgroud)
但现在我想知道是否存在嵌套会更好的情况.就像是:
class DownloadManager():
class DownloadThread:
def foo(self):
pass
def __init__(self):
dwld_threads = []
def create_new_thread():
dwld_threads.append(DownloadManager.DownloadThread())
Run Code Online (Sandbox Code Playgroud)