Erric Gamma 关于resuable code的采访

news2024/10/22 0:00:28

采访地址

The risk of speculating

Bill Venners: The GoF book says, “The key to maximizing reuse lies in anticipating new requirements and changes to existing requirements, and in designing your systems so they can evolve accordingly. To design a system so that it’s robust to such changes, you must consider how the system might need to change over its lifetime. A design that doesn’t take change into account risks major redesign in the future.” That seems contradictory to the XP philosophy.

Erich Gamma: It contradicts absolutely with XP. It says you should think ahead. You should speculate. You should speculate about flexibility. Well yes, I matured too and XP reminds us that it is expensive to speculate about flexibility, so I probably wouldn’t write this exactly this way anymore. To add flexibility, you really have to be able to justify it by a requirement. If you don’t have a requirement up front, then I wouldn’t put a hook for flexibility in my system up front.

But I don’t think XP and patterns are conflicting. It’s how you use patterns. The XP guys have patterns in their toolbox, it’s just that they refactor to the patterns once they need the flexibility. Whereas we said in the book ten years ago, no, you can also anticipate. You start your design and you use them there up-front. In your up-front design you use patterns, and the XP guys don’t do that.

Bill Venners: So what do the XP guys do first, if they don’t use patterns? They just write the code?

Erich Gamma: They write a test.

Bill Venners: Yes, they code up the test. And then when they implement it, they just implement the code to make the test work. Then when they look back, they refactor, and maybe implement a pattern?

Erich Gamma: Or when there’s a new requirement. I really like flexibility that’s requirement driven. That’s also what we do in Eclipse. When it comes to exposing more API, we do that on demand. We expose API gradually. When clients tell us, “Oh, I had to use or duplicate all these internal classes. I really don’t want to do that,” when we see the need, then we say, OK, we’ll make the investment of publishing this as an API, make it a commitment. So I really think about it in smaller steps, we do not want to commit to an API before its time.

Bill Venners: Well, there are speculative requirements. So if you say you’re going to wait until there’s a requirement, doesn’t that simply move the problem? Because someone could say, “Well, we’re going to need this.” They are saying that’s a requirement. But then someone else might say, “Well, do we really need this, yet?” I’m not quite sure I understand when to speculate and when not to speculate. Who decides when a requirement is really a requirement? How do I decide as a programmer?

Erich Gamma: Well, you must have a customer or consumer of what you produce. For Eclipse, our customer is the community who writes plug-ins. And so we interact with them, and also kind of sync with them, based on the concrete uses we know ourselves, what they might want to use. Therefore my recommendation to a programmer is that when you have to speculate, make sure that you have a least one of your clients involved, preferably more. It also helps when I already have something in my hand.

Bill Venners: What do you mean by having something in your hand?

Erich Gamma: I have a concrete example. And then I go and speculate about how to make it more abstract, and not the other way around. Ideally once I have speculated I immediately ask for feedback from my potential clients.

Bill Venners: So you build a concrete example first.

Erich Gamma: Maybe two or three, until it truly hurts. I duplicate the code once. I duplicate it twice. And then, wow, I had to duplicate it again. At this point the abstraction process starts. So, I say, it would be really nice if this class would allow me to plug in this custom behavior so that I do not have to duplicate the rest.

总结

1,不要过度使用设计模式。如果你的需求没有一个例子,需要你抽象扩展,那就不需要花精力去 人为设计 change point>
2, 可以先写一个实例,当发现有重复代码,开始重构。在这过程中,可以抽象,使用设计模式。
3, 极客开发模式,对效率要求极高。而前期对设计模式投入很多时间,会有点牺牲开发的效率。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2220384.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

VideoCLIP-XL:推进视频CLIP模型对长描述的理解

摘要 对比语言-图像预训练(CLIP)已被广泛研究并应用于众多领域。然而,预训练过程中对简短摘要文本的重视阻碍了CLIP理解长描述的能力。在视频方面,这个问题尤为严重,因为视频通常包含大量详细内容。在本文中&#xff…

【JavaEE】——TCP应答报文机制,超时重传机制

阿华代码,不是逆风,就是我疯 你们的点赞收藏是我前进最大的动力!! 希望本文内容能够帮助到你!! 目录 一:TCP协议(面试重点重点) 1:报头长度 2:…

Pytest参数详解 — 基于命令行模式!

1、--collect-only 查看在给定的配置下哪些测试用例会被执行 2、-k 使用表达式来指定希望运行的测试用例。如果测试名是唯一的或者多个测试名的前缀或者后缀相同,可以使用表达式来快速定位,例如: 命令行-k参数.png 3、-m 标记(…

鲸信私有化即时通信如何平衡安全性与易用性之间的关系?

即时通信已经成为我们生活中不可或缺的一部分。从日常沟通到工作协作,每一个信息的传递都承载着信任与效率。然而,随着网络安全威胁日益严峻,如何在享受即时通信便捷的同时,确保信息的私密性与安全性,成为了摆在我们面…

AGV电子地图之贝塞尔曲线

贝塞尔曲线在AGV系统的电子地图中的重要位置 AGV电子地图之贝塞尔曲线_哔哩哔哩_bilibili 点击关注不迷路,你的关注是我们最大的动力 在AGV(自动引导车)系统的电子地图中,贝塞尔曲线有着重要的作用,主要体现在以下几个…

如何保证Redis和数据库的数据一致性

文章目录 0. 前言1. 补充知识:CP和AP2. 什么情况下会出现Redis与数据库数据不一致3. 更新缓存还是删除缓存4. 先操作缓存还是先操作数据库4.1 先操作缓存4.1.1 数据不一致的问题是如何产生的4.1.2 解决方法(延迟双删)4.1.3 最终一致性和强一致…

【大数据算法】一文掌握大数据算法之:大数据算法分析技术。

大数据算法分析技术 1、引言2、 大数据分析技术2.1 时间/空间复杂度2.2 I/O 复杂度2.3 结果质量2.4 通信复杂度 3、总结 1、引言 小屌丝:鱼哥,最近更文有些不频繁了哈。 小鱼:这一个月不见,你这说话方式也变了。 小屌丝&#xff…

C++与C语言的排序算法对比(插入,希尔,归并)

1. 引言 排序算法是计算机科学中的基础概念,广泛应用于数据处理和算法设计中。本文将通过插入排序、希尔排序、归并排序和选择排序这四种常见的排序算法,分别用C和C语言实现,并对它们进行优劣对比,以帮助读者更好地理解这两种语言…

MATLAB支持的字体

listfonts 列出可用的系统字体 {Adobe Devanagari } {Agency FB } {Algerian } {AlienCaret } {AMS } {Arial } {Arial Black …

[LeetCode] 21. 合并两个有序链表

题目描述: 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: 输入:l1 [1,2,4], l2 [1,3,4] 输出:[1,1,2,3,4,4]示例 2: 输入:l1 [], l2 […

数据结构(8.3_1)——冒泡排序

交换排序: 冒泡排序和快速排序 冒泡排序: 示例: 从行往前将A[i-1]和A[i]比较若遇到A[i-1]>A[i]则将两个元素交换 注意: 代码实现: //交换 void swap(int& a, int& b) {int temp a;a b;b temp; } //冒…

入门!Linux 常见指令及权限管理全面指南

Linux 操作系统在现代计算机应用中扮演着重要的角色,广泛用于服务器、桌面系统、嵌入式设备及云计算平台等领域。理解和掌握 Linux 常见指令及权限管理机制,是每一位系统管理员和开发人员的基础技能。本文将详细介绍 Linux 系统的基本背景、常用指令、权…

设计模式概览

设计模式是一种解决常见编程问题的经验总结,提供了代码的可重用性、可扩展性和可维护性。常见的设计模式有23个,主要分为三大类:创建型模式、结构型模式和行为型模式。下面是这三类设计模式的详细分类和讲解: 一、创建型模式 创建…

进入 Searing-66 火焰星球:第一周游戏指南

Alpha 第四季已开启,穿越火焰星球 Searing-66,带你开启火热征程。准备好勇闯炙热的沙漠,那里有无情的高温和无情的挑战在等待着你。从高风险的烹饪对决到炙热的冒险,Searing-66 将把你的耐力推向极限。带上充足的水,天…

Fusion创建一个简单的api脚本文件

我的Fusion版本:Fusion 2.0.20476 x86_64 脚本模块在实用程序->附加模型->脚本和附加模块,快捷键为shifts 里面有一些演示脚本,可以直接使用 也可以自己创建一个新的脚本 创建的脚本在此处—— 选择脚本文件,点击编辑&a…

小新学习Docker之Ansible 的脚本 --- playbook 剧本

一、playbook 剧本简介 playbooks 本身由以下各部分组成: (1)Tasks:任务,即通过 task 调用 ansible 的模板将多个操作组织在一个 playbook 中运行 (2)Variables:变量 (3…

Linux系统基础-动静态库

个人主页:C忠实粉丝 欢迎 点赞👍 收藏✨ 留言✉ 加关注💓本文由 C忠实粉丝 原创 Linux系统基础-动态库和静态库 收录于专栏[Linux学习] 本专栏旨在分享学习Linux的一点学习笔记,欢迎大家在评论区交流讨论💌 目录 1. 动…

如何在 Jupyter Notebook 执行和学习 SQL 语句(下)—— 进阶版题目综合(多表连接,窗口函数,子查询等等)

这是我收藏的一些相关的题目,其中包含基本操作(如创建表、插入数据)(注意一般企业也不会让删除数据啥的,毕竟刚进去哪会让对人家数据库做什么操作,我是实习的时候参加了数据仓库的建设,插了一些…

498.对角线遍历

目录 题目解法代码说明:输出: 如何确定起始点?解释一下max(0,d−m1)是什么意思? 如何遍历对角线?.push_back是怎么用的? 题目 给你一个大小为 m x n 的矩阵 mat ,请以对角线遍历的顺序&#xf…

JNA调用c++动态库返回数据

jna学习网站 JNA Examples 1、返回String, pch.h头文件 // pch.h: 这是预编译标头文件。 // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 // 但是,如果此处…