A Laboratory For Teaching Object-Oriented Thinking

A Laboratory For Teaching
Object-Oriented Thinking

Kent Beck, Apple Computer, Inc.
Ward Cunningham, Wyatt Software Services, Inc.

From the OOPSLA'89 Conference Proceedings
October 1-6, 1989, New Orleans, Louisiana
And the special issue of SIGPLAN Notices
Volume 24, Number 10, October 1989

Contents

  1. Problem
  2. Perspective
  3. CRC Cards
  4. Experience
  5. Conclusion
  6. References
  7. Appendix

Introduction

It is difficult to introduce both novice and experienced procedural programmers to the anthropomorphic perspective necessary for object-oriented design. We introduce CRC cards, which characterize objects by class name, responsibilities, and collaborators, as a way of giving learners a direct experience of objects. We have found this approach successful in teaching novice programmers the concepts of objects, and in introducing experienced programmers to complicated existing designs.

1. Problem

The most difficult problem in teaching object- oriented programming is getting the learner to give up the global knowledge of control that is possible with procedural programs, and rely on the local knowledge of objects to accomplish their tasks. Novice designs are littered with regressions to global thinking: gratuitous global variables, unnecessary pointers, and inappropriate reliance on the implementation of other objects.

Because learning about objects requires such a shift in overall approach, teaching objects reduces to teaching the design of objects. We focus on design whether we are teaching basic concepts to novices or the subtleties of a complicated design to experienced object programmers.

Rather than try to make object design as much like procedural design as possible, we have found that the most effective way of teaching the idiomatic way of thinking with objects is to immerse the learner in the "object-ness" of the material. To do this we must remove as much familiar material as possible, expecting that details such as syntax and programming environment operation will be picked up quickly enough once the fundamentals have been thoroughly understood.

It is in this context that we will describe our perspective on object design, its concrete manifestation, CRC (for Class, Responsibility, and Collaboration) cards, and our experience using these cards to teach both the fundamentals and subtleties of thinking with objects.

2. Perspective

Procedural designs can be characterized at an abstract level as having processes, data flows, and data stores [1], regardless of implementation language or operating environment. We wished to come up with a similar set of fundamental principles for object designs. We settled on three dimensions which identify the role of an object in a design: class name, responsibilities, and collaborators.

The class name of an object creates a vocabulary for discussing a design. Indeed, many people have remarked that object design has more in common with language design than with procedural program design. We urge learners (and spend considerable time ourselves while designing) to find just the right set of words to describe our objects, a set that is internally consistent and evocative in the context of the larger design environment.

Responsibilities identify problems to be solved. The solutions will exist in many versions and refinements. A responsibility serves as a handle for discussing potential solutions. The responsibilities of an object are expressed by a handful of short verb phrases, each containing an active verb. The more that can be expressed by these phrases, the more powerful and concise the design. Again, searching for just the right words is a valuable use of time while designing.

One of the distinguishing features of object design is that no object is an island. All objects stand in relationship to others, on whom they rely for services and control. The last dimension we use in characterizing object designs is the collaborators of an object. We name as collaborators objects which will send or be sent messages in the course of satisfying responsibilities. Collaboration is not necessarily a symmetric relation. For example in Smalltalk- 80 [2], View and Controller operate as near equals (see example below) while OrderedCollection offers a service with little regard or even awareness of its client.

Throughout this paper we deliberately blur the distinction between classes and instances. This informality is not as confusing as it might seem because the concreteness of our method substitutes for naming of instances. This also makes our method for teaching independent of whether a class or prototype-based language is used.

3. CRC Cards

The second author invented CRC cards in response to a need to document collaborative design decisions. The cards started as a HyperCard [3] stack which provided automatic indexing to collaborators, but were moved to their current form to address problems of portability and system independence.

Like our earlier work in documenting the collaboration of objects [4], CRC cards explicitly represent multiple objects simultaneously. However, rather than simply tracing the details of a collaboration in the form of message sending, CRC cards place the designer's focus on the motivation for collaboration by representing (potentially) many messages as a phrase of English text.


Figure 1. A Class-Responsibility-collaborator (CRC) index card

As we currently use them, all the information for an object is written on a 4" x 6" index card. These have the advantages that they are cheap, portable, readily available, and familiar. Figure 1 shows an idealized card. The class name appears underlined in the upper-left hand corner, a bullet- list of responsibilities appears under it in the left two-thirds of the card, and the list of collaborators appears in the right third.


Figure 2. CRC-cards describing the responsibilities and collaborations of Smalltalk's Model, View and Controller.

Figure 2 shows an example taken from the Smalltalk-80 image, the much-misunderstood model-view-controller user interface framework. We have deliberately shown only a portion of the responsibilities each of these objects assumes for clarity of exposition. Note that the cards are placed such that View and Controller are overlapping (implying close collaboration) and placed above Model (implying supervision.) We find these and other informal groupings aid in comprehending a design. Parts, for example, are often arranged below the whole. Likewise, refinements of an abstraction can be collected and handled as a single pile of cards with the most abstract card on top where it can represent the rest.

The ability to quickly organize and spatially address index cards proves most valuable when a design is incomplete or poorly understood. We have watched designers repeatedly refer to a card they intended to write by pointing to where they will put it when completed.

Design with the cards tends to progress from knowns to unknowns, as opposed to top-down or bottom up. We have observed two teams arriving at essentially the same design through nearly opposite sequences, one starting with device drivers, the other with high-level models. The problem demanded a certain set of capabilities which both teams discovered in the course of fulfilling the requirements of the design.

We suggest driving a design toward completion with the aid of execution scenarios. We start with only one or two obvious cards and start playing "what-if". If the situation calls for a responsibility not already covered by one of the objects we either add the responsibility to one of the objects, or create a new object to address that responsibility. If one of the object becomes too cluttered during this process we copy the information on its card to a new card, searching for more concise and powerful ways of saying what the object does. If it is not possible to shrink the information further, but the object is still too complex, we create a new object to assume some of the responsibilities.

We encourage learners to pick up the card whose role they are assuming while "executing" a scenario. It is not unusual to see a designer with a card in each hand, waving them about, making a strong identification with the objects while describing their collaboration.

We stress the importance of creating objects not to meet mythical future needs, but only under the demands of the moment. This ensures that a design contains only as much information as the designer has directly experienced, and avoids premature complexity. Working in teams helps here because a concerned designer can influence team members by suggesting scenarios aimed specifically at suspected weaknesses or omissions.

4. Experience

One of the contexts in which we have used CRC cards is a three-hour class entitled "Thinking with Objects," which is intended for computing professionals who have programmed, but whose jobs do not necessarily involve programming every day. The class proceeds by introducing a data flow example (a school, with processes for teaching and administration) which is then recast in terms of objects with responsibilities and collaborators (such as Teacher, Janitor, and Principal). The class then pairs off and spends an hour designing the objects in an automatic banking machine, an exercise chosen because of everyone's familiarity with the application and its ready breakdown into objects to control the devices, communicate with the central bank database, and control the user interface. (See the appendix for a sample solution.) The exercise is followed by a definition of the terms "class", "instance", "method", and "message", and the class concludes with a brief discussion of the history and features of a variety of object- oriented programming languages.

In teaching over a hundred students this course we have encountered no one who was unable to complete the exercise unaided, although one pair in each class usually needs a few hints to get started. Although we have done no follow-up studies, the class is considered a valuable resource in the company and is still well attended with a long waiting list almost a year after its inception.

We have also asked skilled object programmers to try using CRC cards. Our personal experience suggests a role for cards in software engineering though we cannot yet claim a complete methodology (others [5][6] have more fully developed methodologies that can take advantage of CRC methods). We- know of one case where finished cards were delivered to a client as (partial) design documentation. Although the team that produced the cards was quite happy with the design, the recipient was unable to make sense of the cards out of context.

Another experiment illustrates the importance of the context established by the handling and discussing of cards. We had videotaped experienced designers working out a problem similar to the bank machine. Our camera placement made cards and the designers' hands visible but not the writing on the cards. Viewers of the tape had no trouble following the development and often asked that the tape be stopped so that they could express their opinions. The most telling moments came when a viewer's explanation required that he point to a blurry card in the frozen image on the screen.

Finally, we have used CRC cards to advantage in explaining complex designs. A few minutes of introduction is sufficient to prepare an audience for a card based presentation. Cards can be made out in advance or written on the spot. The latter allows the complexity in a design to be revealed slowly, a process related to Dave Thomas' "lie management". The cards are being used as props to aid the telling of a story of computation. The cards allow its telling without recourse to programming language syntax or idiom.

5. Conclusion

Taking our perspective as a base we give novices and experienced programmers a learning experience which teaches them something valuable about objects. CRC cards give the learner who has never encountered objects a physical understanding of object-ness, and prepares them to understand the vocabulary and details of particular languages. CRC cards also give useful and convincing experience with objects to those who has learned the mechanisms of objects but do not yet see their value.

Ragu Raghavan [7] has said that in the switch to objects strong programmers become stronger, but weaker programmers are left behind. Using the cards in group settings we found that even weaker programmers, without a deep understanding of objects, could contribute to object designs. We speculate that because the designs are so much more concrete, and the logical relationship between objects explicit, it is easier to understand, evaluate, and modify a design.

We were surprised at the value of physically moving the cards around. When learners pick up an object they seem to more readily identify with it, and are prepared to deal with the remainder of the design from its perspective. It is the value of this physical interaction that has led us to resist a computerization of the cards.

It is just this problem-integrating the cards with larger design methodologies and with particular language environments, that we feel holds the most promise for the future. The need to retain the value of physical interaction points to the need for a new kind of user interface and programming environment as far beyond what we have today as our current systems are beyond the tool-oriented environments of the past.

References

[1] DeMarco, T.: Structured Analysis and System Specification, Yourdon, 1978.

[2] Smalltalk-80 image, Xerox Corp, 1983.

[3] HyperCard manual, Apple Computer Inc.

[4] Cunningham, W. and Beck, K.: "A Diagram for Object-Oriented Programs," in Proceedings of OOPSLA-86, October 1986.

[5] Wirfs-Brock, R. and Wilkerson, B. "Object- Oriented Design: a Responsibility-Driven Approach," submitted to OOPSLA '89.

[6] Reenskaug, T.: "A Methodology for the Design and Description of Complex, Object- Oriented Systems," technical report, Center for Industrial Research, Oslo, Norway, November 1988.

[7] Raghavan, R.: "Panel: Experiences with Reusability," in the Proceedings of OOPSLA '88, October, 1988.

Appendix

Here we provide a sample solution to the banking machine problem discussed in section 4.

Account and Transaction provide the banking model. Note that Transaction assumes an active role while money is being dispensed and a passive role thereafter.

Transactions meet their responsibilities with the aid of several objects that serve as device drivers. The Dispenser object, for example, ultimately operates the dispensing device.

The CardReader object reads and decodes the information on the bank card's magnetic strip. A common mistake would be to itemize all of the information stored on the bank card. Card encoding formats must certainly be well thought out and documented. However, for the purpose of designing the objects, we need only identify where that knowledge will be placed in the program.

The RemoteDataBase drives the communication lines and interprets data transmitted across them. It creates Account objects and consumes Transaction objects.

The device drivers signal exceptional or asynchronous events by adding Event objects to a shared queue.

Events drive the human interface by triggering Actions that sequence through Screens. The actual format and sequence of screens will be determined by the user-interface design and will probably vary from bank to bank. We offer objects from which state-machine like interfaces can be built.

Screen objects correspond to the states and Action objects correspond to the transitions. Screens may vary in how they dispatch Actions. Actions themselves will vary in how they process events. Actions ultimately construct Transactions to which they delegate the further operating of the bank machine

Permission to copy without fee all or pan of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to publish, requires a fee and/or specific permission.

01989 ACM 089791-333-7/89/0010/0001 $1.50


ward@c2.com

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
电气设备的测量、控制和实验室使用 - EMC要求(电磁兼容性要求) 电气设备的测量、控制和实验室使用需要符合电磁兼容性(EMC)要求。电磁兼容性是指在设备之间达到相对的电磁环境和电磁效能的共存,以确保设备能够在电磁环境中正常工作并避免相互影响。 为了满足EMC要求,电气设备需要进行电磁干扰分析和电磁辐射评估。电磁干扰分析包括评估设备产生的电磁干扰,并采取适当的措施来减少或消除这些干扰。电磁辐射评估则是通过测量设备产生的电磁辐射水平,以确保其不会超出指定的法规和标准。 为了满足EMC要求,电气设备还需要采用电磁屏蔽和过滤技术。电磁屏蔽是通过使用屏蔽材料或设计屏蔽结构来阻隔外部电磁干扰的进入或内部电磁干扰的泄漏。过滤技术是通过电路设计和使用滤波器来消除设备产生的电磁噪声,确保电气设备不会对其他设备造成不良影响。 此外,电气设备还需要进行电磁兼容性测试与认证。这些测试包括发射和抗扰度测试,目的是验证设备在电磁环境中的性能。认证是指通过获得符合国际标准的认证,证明设备满足EMC要求,并可在市场上销售和使用。 总而言之,电气设备的测量、控制和实验室使用需要满足EMC要求,以确保设备在电磁环境中的正常工作和避免相互干扰。这需要进行电磁干扰分析、辐射评估,采用电磁屏蔽和过滤技术,并进行认证测试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值