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
URL链接:https://www.cdcxhl.com/article8/gpisop.html

成都网站建设公司_创新互联,为您提供外贸网站建设搜索引擎优化网站收录品牌网站建设软件开发网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司