计算机科学

首页 > 计算机科学

Mixin

2018-08-31 10:19:30     所属分类:面向对象的程序设计

Mixin鏄?a href="/wiki/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E8%AF%AD%E8%A8%80" class="mw-redirect" title="闈㈠悜瀵硅薄绋嬪簭璁捐璇█">闈㈠悜瀵硅薄绋嬪簭璁捐璇█涓殑绫?/a>锛屾彁渚涗簡鏂规硶鐨勫疄鐜般€傚叾浠栫被鍙互璁块棶mixin绫荤殑鏂规硶鑰屼笉蹇呮垚涓哄叾瀛愮被銆?sup id="cite_ref-1" class="reference">[1]Mixin鏈夋椂琚О浣?included"鑰屼笉鏄?inherited"銆俶ixin涓轰娇鐢ㄥ畠鐨刢lass鎻愪緵棰濆鐨勫姛鑳斤紝浣嗚嚜韬嵈涓嶅崟鐙娇鐢紙涓嶈兘鍗曠嫭鐢熸垚瀹炰緥瀵硅薄锛屽睘浜庢娊璞$被锛夈€傚洜涓烘湁浠ヤ笂闄愬埗锛孧ixin绫婚€氬父浣滀负鍔熻兘妯″潡浣跨敤锛屽湪闇€瑕佽鍔熻兘鏃垛€滄贩鍏モ€濓紝鑰屼笖涓嶄細浣跨被鐨勫叧绯诲彉寰楀鏉傘€備娇鐢ㄨ€呬笌Mixin涓嶆槸鈥渋s-a鈥濈殑鍏崇郴锛岃€屾槸鈥?able鈥濆叧绯?

Mixin鏈夊埄浜?a href="/wiki/%E4%BB%A3%E7%A0%81%E5%A4%8D%E7%94%A8" title="浠g爜澶嶇敤">浠g爜澶嶇敤[2]鍙堥伩鍏嶄簡澶氱户鎵?/a>鐨勫鏉傘€?sup id="cite_ref-3" class="reference">[3][4]浣跨敤Mixin浜湁鍗曚竴缁ф壙鐨勫崟绾€у拰澶氶噸缁ф壙鐨勫叡鏈夋€с€傛帴鍙d笌mixin鐩稿悓鐨勫湴鏂规槸閮藉彲浠ュ缁ф壙锛屼笉鍚岀殑鍦版柟鍦ㄤ簬 mixin 鏄甫瀹炵幇鐨勩€侻ixin涔熷彲浠ョ湅浣滄槸甯﹀疄鐜扮殑interface锛?span class="ilh-lang">鑻辫锛?/span>Interface (object-oriented programming)锛?/span>銆傝繖绉?a href="/wiki/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F" class="mw-disambig" title="璁捐妯″紡">璁捐妯″紡瀹炵幇浜?a href="/wiki/%E4%BE%9D%E8%B5%96%E5%8F%8D%E8%BD%AC%E5%8E%9F%E5%88%99" title="渚濊禆鍙嶈浆鍘熷垯">渚濊禆鍙嶈浆鍘熷垯銆?sup id="cite_ref-5" class="reference">[5]

鐩綍

  • 1 鍘嗗彶
  • 2 瀹炵幇
  • 3 缂栫▼璇█鏀寔
  • 4 渚嬪瓙
    • 4.1 Common Lisp
    • 4.2 Python
    • 4.3 Ruby
    • 4.4 JavaScript
    • 4.5 鍏朵粬璇█
  • 5 鎺ュ彛涓巘rait
    • 5.1 Scala
    • 5.2 Swift
  • 6 鍙傝
  • 7 鍙傝€冩枃鐚?/span>
  • 8 澶栭儴閾炬帴

鍘嗗彶缂栬緫

Mixin鏈€鍒濆嚭鐜板湪Symbolics锛?span class="ilh-lang">鑻辫锛?/span>Symbolics锛?/span>鐨勯潰鍚戝璞?span class="ilh-all" data-orig-title="Flavors" data-lang-code="en" data-lang-name="鑻辫" data-foreign-title="Flavors (programming language)">Flavors锛?span class="ilh-lang">鑻辫锛?/span>Flavors (programming language)锛?/span>绯荤粺锛堢敱Howard Cannon寮€鍙戯級锛屼娇鐢ㄤ簡Lisp Machine Lisp锛?span class="ilh-lang">鑻辫锛?/span>Lisp Machine Lisp锛?/span>鐨勯潰鍚戝璞℃柟娉曘€傚悕绉拌捣婧愪簬椹惃璇稿宸?a href="/wiki/%E8%90%A8%E9%BB%98%E7%BB%B4%E5%B0%94_(%E9%A9%AC%E8%90%A8%E8%AF%B8%E5%A1%9E%E5%B7%9E)" title="钀ㄩ粯缁村皵 (椹惃璇稿宸?">钀ㄩ粯缁村皵_(椹惃璇稿宸?鐨?span class="ilh-all" data-orig-title="Steve's Ice Cream" data-lang-code="en" data-lang-name="鑻辫" data-foreign-title="Steve's Ice Cream">Steve's Ice Cream锛?span class="ilh-lang">鑻辫锛?/span>Steve's Ice Cream锛?/span>锛?sup id="cite_ref-6" class="reference">[6] 杩欏鍐版穱娣嬪簵鎻愪緵鍩烘湰鍙e懗鐨勫啺娣囨穻锛堥鑽夈€佸阀鍏嬪姏绛夛級锛屾贩鍚堝叆鍏朵粬棰濆鎴愬垎锛堝潥鏋溿€佹洸濂囥€?a href="/wiki/%E4%B9%B3%E8%84%82%E8%BB%9F%E7%B3%96" title="涔宠剛杞硸">涔宠剛杞硸绛夛級骞剁О杩欎簺涓?mix-in锛?span class="ilh-lang">鑻辫锛?/span>mix-in锛?/span>",杩樻敞鍐屼簡鍟嗘爣銆?sup id="cite_ref-7" class="reference">[7]

瀹炵幇缂栬緫

缂栫▼璇█鏀寔缂栬緫

闄や簡Flavors涓嶤LOS (浣滀负Common Lisp鐨勯儴鍒?锛屽叾浠栬瑷€鐨勬敮鎸?

  • Ada璇█ (鎵╁睍宸插瓨鍦ㄧ殑tagged record)
  • Cobra
  • ColdFusion (鍩轰簬绫荤殑includes锛屽熀浜庡璞$殑璧嬪€兼柟娉?
  • Curl (Curl RTE)
  • D璇█ (绉颁綔"template mixins"; D璇█鍖呭惈"mixin"璇彞.)
  • Dart
  • Factor璇█锛?span class="ilh-lang">鑻辫锛?/span>Factor programming language锛?/span>[9]
  • Groovy
  • JavaScript Delegation - Functions 浣滀负 Roles (Traits 涓?Mixins)
  • OCaml
  • Perl (閫氳繃 Moose_(Perl)锛?span class="ilh-lang">鑻辫锛?/span>Moose_(Perl)锛?/span>鐨剅oles)
  • Perl 6
  • PHP鐨?Trait"
  • Python璇█
  • Racket (mixins documentation)
  • Ruby璇█
  • Scala[10]
  • XOTcl锛?span class="ilh-lang">鑻辫锛?/span>XOTcl锛?/span>/TclOO [11]
  • Sass
  • Vala
  • Swift
  • SystemVerilog

涓€浜涜瑷€鍏佽杩愯鏃朵粠涓€涓璞℃嫹璐濇柟娉曞埌鍙︿竴涓璞°€傝繖鍙互鈥滃€熲€漨ixin鐨勬柟娉曘€?

C#涓?a href="/wiki/Visual_Basic.NET" class="mw-redirect" title="Visual Basic.NET">Visual Basic.NET鏀寔鎺ュ彛鐨勬墿灞曟柟娉曪紙extension method锛夈€?

渚嬪瓙缂栬緫

Common Lisp缂栬緫

Python缂栬緫

python涓紝闄や簡protocol锛屼篃鍙互鐢ㄥ缁ф壙鐨勫舰寮忔潵瀹炵幇Mixin銆備负浜嗗尯鍒嗘櫘閫氱殑澶氱户鎵匡紝Mixin绫荤殑绫诲悕涓€鑸兘浼氬甫涓婂悗缂€锛氣€淢ixin鈥濓紝姣斿python lib閲岄潰鐨勪袱涓狹ixin绫伙細UserDict.DictMixin銆侱ictMixin绫诲寘鎷儴鍒嗗疄鐜帮紝浣跨敤鑰呯殑绫诲彧瑕佸疄鐜板嚑涓繀椤荤殑鍑芥暟鎺ュ彛锛屽锛歡etitem, setitem, delitem, keys銆?

Python璇█鐨?code>SocketServer妯″潡[12]鎻愪緵浜?code>UDPServer绫讳笌TCPServer绫伙紝浣滀负UDP涓?a href="/wiki/Transmission_Control_Protocol" class="mw-redirect" title="Transmission Control Protocol">TCP鐨剆ocket鏈嶅姟鍣ㄣ€傛湁涓や釜mixin绫伙細ForkingMixIn涓?ThreadingMixIn銆傚鏋滃埌鏉ョ殑connection鏈夌嚎绋嬫潵澶勭悊锛?code>TCPServer涓?code>ThreadingMixIn濡備笅浣跨敤锛?

class ThreadingTCPServer(ThreadingMixIn, TCPServer):
  pass

浣跨敤ForkingMixIn浼?a href="/wiki/Fork_(%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8)" title="Fork (绯荤粺璋冪敤)">fork鏂扮嚎绋嬪鐞嗘柊鐨刢onnection銆?

Ruby缂栬緫

鍦╮uby涓紝骞朵笉鐩存帴浣跨敤Mixin杩欎釜鍗曡瘝锛岃€屾槸浣跨敤鍦ㄧ被鐨勫0鏄庝腑include涓€涓猰odule鐨勫姙娉曘€?

JavaScript缂栬緫

鍏朵粬璇█缂栬緫


上一篇:鸭子类型
下一篇:Modelica
相关推荐