倍可親

dd

作者:pidy  於 2022-9-4 13:31 發表於 最熱鬧的華人社交網路--貝殼村

通用分類:政經軍事

四人幫

這可能很難記住,但面向對象編程在 1990 年代風靡一時。許多程序員沒有談論一流函數和通用數據結構的力量,而是用虛方法、超類、子類和巧妙的 mixin 來裝飾他們的代碼。程序員經常發現語言限制和靜態類型使他們無法對代碼進行改進。

「四人幫」趕來救援。他們的書的第一個也是最基本的模式,在整個頁面上用斜體標出,如果堅持實踐的話,將讓程序員擺脫硬連接到具體類的代碼:

「編程到介面,而不是實現。」

這種做法以更多代碼為代價,使程序員朝著我們在 Python 這樣的動態語言中享受的自由邁出了一步。本書後面的每一章都解決了這個時代有限的編程語言帶來的不同設計難題並解決了它。大多數解決方案都引入了新類,以巧妙地解耦原本鏈接過於緊密的代碼。

該站點在現代動態編程語言的上下文中檢查四人幫的舊模式,其中類和函數是一流的對象,以查看哪些模式仍然有用,哪些模式消失了。您可以回到本網站的首頁開始研究這些模式

Gang of Four book

It can be hard to remember, but object oriented programming was all the rage back in the roaring 1990s. Instead of talking about the power of first-class functions and general-purpose data structures, many programmers were festooning their code with virtual methods, superclasses, subclasses, and clever mixins. Programmers often found that language limitations and static types were locking them out of improvements they later wanted to make to their code.

The 「Gang of Four」 rode to the rescue. Their book』s first and most fundamental pattern, blazoned across the page in italics, would — if practiced consistently — break programmers free of code that was hard-wired to concrete classes:

「Program to an interface, not an implementation.」

At the expense of more code, this practice moved programmers one step towards the freedom we enjoy in a dynamic language like Python. Each of the book』s further chapters tackled a different design conundrum posed by the era』s limited programming languages and solved it. Most of the solutions introduced new classes to cleverly decouple code that would otherwise be too tightly linked.

This site examines the old patterns from the Gang of Four in the context of a modern dynamic programming language in which classes and functions are first-class objects, to see which patterns are still useful and which ones disappear. You can start working through the patterns back on this site』s front page.




高興

感動

同情

搞笑

難過

拍磚

支持

鮮花

評論 (0 個評論)

facelist doodle 塗鴉板

您需要登錄后才可以評論 登錄 | 註冊

關於本站 | 隱私權政策 | 免責條款 | 版權聲明 | 聯絡我們

Copyright © 2001-2013 海外華人中文門戶:倍可親 (http://big5.backchina.com) All Rights Reserved.

程序系統基於 Discuz! X3.1 商業版 優化 Discuz! © 2001-2013 Comsenz Inc.

本站時間採用京港台時間 GMT+8, 2024-5-23 00:21

返回頂部