我们看到很多面向对象编程的"优秀的项目" (https://link.segmentfault.com/?enc=TSXB322kwDO%2FKB5UXdAesg%3D%3D.QXBcWZY3fJMV72IMgW4jz3r3H0%2FP80%2FTeSxIzRfeByMzfSccEDyEEiF0eqfYz3hyVTHCf39pgqtTeT5D5Aj658ZhZu9D%2Bu9vw5KztaWJ22C3ApZ11CL8ZPjs0tIEsHyFpp2UhpTwrbq9WH63W47Org6NE00T2bGKAoYYtabKLtw%3D), 我们看到一个类继承一个类地,并且传递的类实例,看起来是相当庞大的项目,拥有相当多设计好的类,并且每个类设计的都很好: "QQ20240809-222225.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240917/6716dac33dbc6b38e34b1a746c311c8d.png) 但是比如我这等初级程序员,设计项目的时候, 1、根本很难把一个类设计的很好 2、想不到很多的接口继承或类实现接口的设计 3、比如在设计这个类的时候: class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider { public constructor( private readonly client: ITypeScriptServiceClient, private readonly cachedResponse: CachedResponse, ) { } public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise { const file = this.client.toOpenTsFilePath(document); if (!file) { return undefined; } const args: Proto.FileRequestArgs = { file }; const response = await this.cachedResponse.execute(document, () => this.client.execute('navtree', args, token)); if (response.type !== 'response' || !response.body?.childItems) { return undefined; } // The root represents the file. Ignore this when showing in the UI const result: vscode.DocumentSymbol[] = []; for (const item of response.body.childItems) { TypeScriptDocumentSymbolProvider.convertNavTree(document.uri, result, item); } return result; } 1)不会想到:"private readonly "这些字段的功能,不会纳入类设计 2)不会想到泛型的利用 private readonly cachedResponse: CachedResponse 3)比如这个参数:是有固定的类依据,如果是我的话,会可能直接想到传输string或者number这样的初级的类型:这些优秀的软件工程师为何就能思考到使用"document: vscode.TextDocument" 这样的高级参数呢? public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken) 4)比如返回的这个值,是这样,我看都看不懂,他们是基于什么来进行设计的呢?是在设计的时候就想要一个什么样的形式结果(eg. ": Promise")再进行设计的是吗? : Promise