内容 2.1 Introduction to Data Abstraction · 76
练习 自检推理
Exercise 2.3: Implement a representation for
rectangles in a plane. (Hint: You may want to make use of Exercise 2.2.)
In terms of your constructors and selectors, create procedures that compute the
perimeter and the area of a given rectangle. Now implement a different
representation for rectangles. Can you design your system with suitable
abstraction barriers, so that the same perimeter and area procedures will work
using either representation?
练习 2.3:实现平面上矩形的一种表示。(提示:可以利用练习 2.2。)基于你的构造函数和选择函数,创建能计算给定矩形周长和面积的过程。接下来,再实现矩形的另一种表示。你能否通过设置合适的抽象屏障,使同一套周长和面积过程在两种表示下都能正常工作?
我的笔记 自动保存