C# Fluent Interface怎么实现
发表于:2024-10-02 作者:千家信息网编辑
千家信息网最后更新 2024年10月02日,这篇文章主要介绍"C# Fluent Interface怎么实现",在日常操作中,相信很多人在C# Fluent Interface怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法
千家信息网最后更新 2024年10月02日C# Fluent Interface怎么实现
这篇文章主要介绍"C# Fluent Interface怎么实现",在日常操作中,相信很多人在C# Fluent Interface怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"C# Fluent Interface怎么实现"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
C# Fluent Interface代码实现:
public interface IRect { void SetWidth(int width); void SetHeight(int height); } public Rect : IRect { private int _width; private int _height; public void SetWidth(int width) { this._width = width; } public void SetHeight(int height){ this_height = height; } } public static void Main(string [] args) { IRect rect = new Rect(); rect.SetHeight(10); rect.SetWidth(50); }
没有什么花俏的东西,一个可设长宽的矩形接口并提供一个简单实现。接下来看看用另一种方式
public interface IRectFluent { IRectFluent SetWidth(int width); IRectFluent SetHeight(int height); } public RectFluent : IRectFluent { private int _width; private int _height; public IRectFluent SetWidth(int width) { this._width = width; return this; } public IRectFluent SetHeight(int height){ this_height = height; return this; } } public static void Main(string [] args) { IRectFluent rect = new RectFluent(); rect.SetHeight(10).SetWidth(50); // checkpoint }
这种"链式"方法调用方式是不是更接近我们人脑的思维方式,更简洁呢。没错, It's Fluent Interface。
个人理解的Fluent Interface 就是 在面向对象编程中,使用某种方式(通常但不限于使用 方法链方式)来实现更具可读性,易用性的编程方式。而方法链的关键之处就是在方法内部调用***要返回调用者本身。
所谓Fluent借助于wikipedia的说法就是'This style is beneficial due to its ability to provide a more fluid feel to the code."
说到这里,经常使用jquery的朋友肯定感觉很熟悉上面的使用方式。
没错,类似于 $('id').show().css('').fadeOut(); 这种就是一种Fluent Interface实现。
到此,关于"C# Fluent Interface怎么实现"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
方式
C#
方法
就是
学习
接下来
更多
帮助
编程
实用
简洁
花俏
东西
个人
人脑
代码
关键
可读性
对象
思维
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
山西常见软件开发收费
优质管理软件开发哪家好
自考数据库系统原理书本答案
济南嵌入式软件开发教程
服务器如何更换账户名
永丰租房网络安全
服务器 维保
数据库软件都有什么
mu 奇迹 服务器
无法打开数据库什么意思
软件开发的任职要求
sql数据库复制图解
电子工程师和软件开发工程师
数据库中的多对多关系
服务器安全狗拦截ddos
托蒂视频软件开发
青娱乐视频软件开发
蜜芽宝贝中国网络技术有限公司
5g虚拟网络技术
组装高性能nas服务器
网络安全在我心中快板
重庆邮电大学数据库资源
证券行业做软件开发
CV4014电子管数据库
酒店网络安全需求分析
考驾照软件开发商
大学代理服务器
神经网络软件开发技术
scum服务器管理员代码
数据库服务器名称去哪里看