fluent 界面控件_使用Fluent界面设计模式使代码更简洁易读

fluent 界面控件

The Fluent Interface Design Pattern

流利的界面设计模式

You can use the Fluent Interface design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that resembles message handling, where a message is passed from program to program, with each program adding a bit of value to the message.  It was first given its name about a decade ago by Martin Fowler, and is now in wide use in the PHP world, considered a "best practice" by industry leaders.  Fluent design allows us to do rapid application development with Laravel, and facilitates formalized automated application testing with PHPUnit.  One of the defining principles of the design pattern is code that is "primarily designed to be readable and to flow."  One of the most delightful effects of using a Fluent Interface design is the elegant simplicity of method chaining.

您可以使用Fluent Interface设计模式使您PHP代码更易于阅读和维护。 “ Fluent接口”是一种类似于消息处理的面向对象的设计模式,在该模式中,消息从一个程序传递到另一个程序,每个程序都为该消息添加一些值。 它大约是十年前由Martin Fowler命名的,现在在PHP世界中被广泛使用,被业界领导者视为“最佳实践”。 流利的设计使我们能够使用Laravel进行快速的应用程序开发,并借助PHPUnit促进形式化的自动化应用程序测试 。 设计模式的定义原则之一是“最初设计为易于阅读和流动的代码”。 使用Fluent接口设计最令人愉悦的效果之一就是方法链接的优雅简洁性。

Before we see a Fluent Interface in practice, let's look at some programming activities we have all encountered before, and the steps (and missteps) we have used to solve our problems.  A good example is the Address Book or Contact Directory.  When we start writing this application, we think, "Well, I need names and phone numbers."  And that is fine for starters, but right after you get it all set up, the boss comes in.  "Don't forget that you also need email addresses."  

在实践中看到Fluent接口之前,让我们看一下之前所有遇到的编程活动,以及用于解决问题的步骤(和错误步骤)。 通讯录或联系人目录就是一个很好的例子。 当我们开始编写此应用程序时,我们会想到:“好,我需要姓名和电话号码。” 这对初学者来说很好,但是当您完成所有设置后,老板就会加入。“别忘了,您还需要电子邮件地址。”

OK, no problem, we can add that field to our data model.

好的,没问题,我们可以将该字段添加到我们的数据模型中。

Here's what an original data model might look like (in prototype):

这是原始数据模型的外观(在原型中):

<?php
$name = 'Ray';
$phone = '703.555.1212';
$email = 'ray@gmail.com';

Of course, we will need more than one name in our directory.

当然,我们的目录中将需要多个名称。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值