偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

C# Fluent Interface概念實(shí)例淺析

開(kāi)發(fā) 后端
C# Fluent Interface是什么呢?對(duì)于C# Fluent Interface我們是如何實(shí)現(xiàn)的呢?那么本文就向你詳細(xì)介紹相關(guān)內(nèi)容。

C# Fluent Interface是如何實(shí)現(xiàn)的呢?首先我們來(lái)看看Fluent Interface,直譯過(guò)來(lái)是 “流暢(流利)的接口”,照字面有點(diǎn)難以理解,那么Fluent Interface是如何實(shí)現(xiàn)的呢?下面讓我們從代碼上向你介紹:

C# Fluent Interface代碼實(shí)現(xiàn):

  1. public interface IRect  
  2. {  
  3. void SetWidth(int width);  
  4. void SetHeight(int height);  
  5. }  
  6. public Rect : IRect  
  7. {  
  8. private int _width;  
  9. private int _height;  
  10. public void SetWidth(int width) { this._width = width; }  
  11. public void SetHeight(int height){ this_height = height; }  
  12. }  
  13. public static void Main(string [] args)  
  14. {  
  15. IRect rect = new Rect();  
  16. rect.SetHeight(10);  
  17. rect.SetWidth(50);  

沒(méi)有什么花俏的東西,一個(gè)可設(shè)長(zhǎng)寬的矩形接口并提供一個(gè)簡(jiǎn)單實(shí)現(xiàn)。接下來(lái)看看用另一種方式

  1. public interface IRectFluent  
  2. {  
  3. IRectFluent SetWidth(int width);  
  4. IRectFluent SetHeight(int height);  
  5. }  
  6. public RectFluent : IRectFluent  
  7. {  
  8. private int _width;  
  9. private int _height;  
  10. public IRectFluent SetWidth(int width) { this._width = width; return this; }  
  11. public IRectFluent SetHeight(int height){ this_height = height; return this; }  
  12. }  
  13. public static void Main(string [] args)  
  14. {  
  15. IRectFluent rect = new RectFluent();  
  16. rect.SetHeight(10).SetWidth(50);  // checkpoint  

這種“鏈?zhǔn)?方法調(diào)用方式是不是更接近我們?nèi)四X的思維方式,更簡(jiǎn)潔呢。沒(méi)錯(cuò), It's Fluent Interface。

個(gè)人理解的Fluent Interface 就是 在面向?qū)ο缶幊讨?,使用某種方式(通常但不限于使用 方法鏈方式)來(lái)實(shí)現(xiàn)更具可讀性,易用性的編程方式。而方法鏈的關(guān)鍵之處就是在方法內(nèi)部調(diào)用***要返回調(diào)用者本身。

所謂Fluent借助于wikipedia的說(shuō)法就是‘This style is beneficial due to its ability to provide a more fluid feel to the code."
說(shuō)到這里,經(jīng)常使用jquery的朋友肯定感覺(jué)很熟悉上面的使用方式。

沒(méi)錯(cuò),類(lèi)似于 $('id').show().css('').fadeOut(); 這種就是一種Fluent Interface實(shí)現(xiàn)。

C# Fluent Interface的相關(guān)內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# Fluent Interface有所幫助。

【編輯推薦】

  1. C# interface學(xué)習(xí)經(jīng)驗(yàn)淺談
  2. C# interface使用實(shí)例分析
  3. 淺析abstract class和interface的不同
  4. 詳解abstract class和interface的本質(zhì)
  5. 關(guān)于interface繼承來(lái)源的討論
責(zé)任編輯:仲衡 來(lái)源: 博客園
相關(guān)推薦

2009-08-27 13:30:11

C# interfac

2009-08-27 14:12:02

C# interfac

2009-08-27 15:17:18

C# interfacinterface使用

2009-09-14 13:44:14

Lambda ExprC# Lambda

2009-08-27 17:59:56

C#接口定義

2009-08-18 13:49:21

C# 操作Excel

2009-08-17 17:49:20

C# 枚舉

2009-09-09 13:57:28

C# XML解析

2009-09-02 10:58:02

C#動(dòng)態(tài)數(shù)組

2009-08-24 14:26:42

C# 泛型類(lèi)

2009-09-09 16:46:59

C# XmlSeria

2009-08-19 11:13:49

C#操作Word

2009-08-31 18:38:59

C#寫(xiě)文件

2009-08-12 15:26:38

C#讀取XML文檔

2009-09-03 14:55:34

C#計(jì)算時(shí)間間隔

2009-08-19 11:34:06

C#操作Word

2009-09-01 13:13:28

C#打開(kāi)Word文檔

2009-08-26 14:16:17

C# FrameWor

2009-08-18 09:51:18

C#枚舉類(lèi)型

2009-08-20 18:47:19

C#異步通信
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)