designpatterninruby

 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

当前名称:designpatterninruby
文章网址:http://bzwzjz.com/article/gpisop.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 移动手机网站制作 成都网站制作 成都网站建设 教育网站设计方案 成都企业网站建设公司 成都网站建设 网站建设公司 成都网站建设 成都网站建设公司 成都品牌网站设计 成都网站制作 成都企业网站设计 品牌网站建设 成都定制网站建设 成都网站设计 达州网站设计 高端网站设计推广 企业网站设计 定制网站建设多少钱 重庆网站建设 专业网站设计 温江网站设计