How Design Patterns Solve Design Problems 设计模式如何解决设计问题

HowDesign Patterns Solve Design Problems

设计模式如何解决设计问题

Design patterns solve many of theday-to-day problems object-oriented designers face, and in many different ways. Here areseveral of these problems and how design patterns solve them.

设计模式解决很多日常的面向对象设计问题,并且用多种方法。在这里有几个问题并且告知设计模式是如何解决这些问题。

FindingAppropriate Objects

寻找合适的对象

Object-oriented programs are made up ofobjects. An object packages both data and the procedures that operate on that data. The procedures are typically called methodsor operations. An object performs an operation when it receives a request

(or message) from a client.

面向对象程序是由对象组成的。对象含有数据和操作这些数据的过程。这种过程被称为方法或运算。当从客户端接收到命令时,对象就执行这种操作。

Requests are the only way to get an objectto execute an operation. Operations are the only way to change an object'sinternal data. Because of these restrictions, the object's internal state is said to beencapsulated; it cannot be accessed directly, and its representation isinvisible from outside the object.

命令仅仅只是让对象完成运算的一种方法。运算仅仅只是改变对象内部数据的一种方法。由于这些约束,对象的内部数据被封装。它不能立即被被获取,它只能被外部对象隐匿的处理。

The hard part about object-oriented designis decomposing a system into objects. The task is difficult because many factorscome into play: encapsulation, granularity, dependency, flexibility,performance, evolution, reusability, and on and on. They all influence thedecomposition, often in conflicting ways.

面向对象设计最难得部分是将系统分解成对象。这项工作难就难在有很多因素在起作用:封装,粒度,依赖性,灵活性,性能,演化,可重用性,等等。这所有的一切都影响分解,并且这些经常是发生冲突的方式。


Object-oriented design methodologies favormany different approaches. You can write a problem statement, single out thenouns and verbs, and create corresponding classes and operations. Or you can focus onthe collaborations and responsibilities in your system. Or you can model the realworld and translate the objects found during analysis into design. There willalways be disagreement on which approach is best.

面向对象设计方法对很多路径都给予关注。你可以写一个问题陈述,单独的名词或动词,创建对应的类和运算。在系统中,你可以关注合作和责任。当你通过分析把它纳入设计之中是,你可以给真实的世界做模型并且翻译发现的对象。这些在把一个设计做成最好的之前总是有冲突。

Many objects in a design come from theanalysis model. But object-oriented designs often end up with classes that have nocounterparts in the real world. Some of these are low-level classes like arrays.Others are much higher-level. For example,

the Composite (183) pattern introduces anabstraction for treating objects uniformly that doesn't have a physicalcounterpart. Strict modeling of the real world leads to a system that reflectstoday's realities but not necessarily tomorrow's. The abstractions that emergeduring design are key to making a design flexible.

设计中的很多对象来自于分析模型。但是面向对象设计总是以在现实世界中不能一视同仁的类结束。有一些是低水平的类像数组,其他的是高水平,例如,抽象的综合的模式介绍是为了均衡的对待那些没有物理副本的对象。现实世界中的严格的建模导致的系统反映了今天的现实,但不一定是明天的。在进行设计时的关键是出现的抽象,它会让设计更灵活。

Design patterns help you identifyless-obvious abstractions and the objects that can capture them. For example, objects thatrepresent a process or algorithm don't occur in nature, yet they are a crucialpart of flexible designs. The Strategy(349) pattern describes how to implementinterchangeable families of algorithms. The State (338) pattern represents eachstate of an entity as an object. Theseobjects are seldom found during analysis oreven the early stages of design; they're discovered later in the course of making adesign more flexible and reusable.

设计模式帮助你抓住不太明显的抽象和对象。例如,对象是在实际中不会出现的进程和算法的规范,这些是灵活的设计中关键的一部分。349页的方案模式描述了如何实现家族式的算法。388页的状态模式描述了实体对象出现的每一种状态。这些对象在分析或早期的设计是不太容易被发现。这些对象在使设计更加灵活、更能重用的过程中被发现了。

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值