design pattern in ruby

简介:
 general principles, to four points: 
• Separate out the things that change from those that stay the same. 
• Program to an interface, not an implementation. 
• Prefer composition over inheritance. 
• Delegate, delegate, delegate. 
following sections, we will look at each of these principles in turn, to see 
what they can tell us about building software.
Separate Out the Things That Change from Those 
That Stay the Same 
Software engineering would be a lot easier if only things would stay the same. We 
could build our classes serene in the knowledge that, once finished, they would continue to do exactly what we built them to do. Of course, things never stay the same, 
not in the wider world and certainly not in software engineering. Changes in com- 
puting hardware, operating systems, and compilers, combined with ongoing bug fixes and ever-migrating requirements, all take their toll. 
A key goal of software engineering is to build systems that allow us to contain the 
damage. In an ideal system, all changes are local: You should never have to comb 
through all of the code because A changed, which required you to change B, which 
triggered a change in C, which rippled all the way down to Z. So how do you achieve— or at least get closer to—that ideal system, the one where all changes are local? 
You get there by separating the things that are likely to change from the things 
that are likely to stay the same. If you can identify which aspects of your system design 
are likely to change, you can isolate those bits from the more stable parts. When 
requirements change or a bug fix comes along, you will still have to modify your code, 
but perhaps, just perhaps, the changes can be confined to those walled-off, change-prone areas and the rest of your code can live on in stable peace. 
But how do you effect this quarantine? How do you keep the changing parts from 
infecting the stable parts? 
Program to an Interface, Not an Implementation 
A good start is to write code that is less tightly coupled to itself in the first place. If our 
classes are to do anything significant, they need to know about each other. But what




本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/73334,如需转载请自行联系原作者
目录
相关文章
|
IDE Java Linux
Ruby Programming | 连载 01 - Intro and Setup
Ruby Programming | 连载 01 - Intro and Setup
Ruby Programming | 连载 01 - Intro and Setup
|
Web App开发 人工智能 测试技术
书籍:Learn Web Development with Python - 2018.pdf
简介 使用最流行的Python Web框架(Django)进行Web编程的Python编程综合指南 主要特点 了解使用Python编程和构建Web应用程序的基础知识 使用Django从头开始构建Web应用程序 使用最新的Django框架创建真实的RESTful Web服务 图书说明 如果您想使用Django开发完整的Python Web应用程序,这个学习路径适合您。
|
Python
python 详解re模块
原文地址:python 详解re模块作者:Rocky 正则表达式的元字符有. ^ $ * ? { [ ] | ( ) .表示任意字符 []用来匹配一个指定的字符类别,所谓的字符类别就是你想匹配的一个字符集,对于字符集中的字符可以理解成或的关系。
1175 0