函数式编程语言及设计策略解析
1. 类的示例
以 Java 语言为例,来看一个类的示例:
public class Rectangle extends Shape {
private float length;
private float width;
public Rectangle (float length, float width) {
this.length = length;
this.width = width;
}
public float getLength () {
return length;
}
public float getWidth () {
return width;
}
public float perimeter () {
perimeter (length, width);
// just in case the class calculation changes
}
public static float perimeter (float length, float width) {
return (2 * (length + width));
}
public float area () {
area (length, width);
// just in case the class calculation changes
}
public
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



