优雅编程之这样使用类和接口，你就“正常”了（三十）

2017-01-13 14:58:49来源:csdn作者:huangwenyi1010人点击

【悬崖上一只小老鼠挥舞着短短的前爪，一次又一次跳下去，努力学习飞翔，旁边母蝙蝠看着它摔的头破血流，忧心的说：它爹，要不告诉它，它不是咱亲生的！】

private static final Thing[] PRIVATE_VALUES = { .... }public static final List<Thing> VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));

private static final Thing[] PRIVATE_VALUES = { .... }public static final Thing[] values(){
return PRIVATE_VALUES.clone();
}

class Point{
public double x;
public double y;}

class Point{private double x;
private double y;public Point(double x, double y) {
this.x = x;
this.y = y;
}public double getX() {
return x;
}public void setX(double x) {
this.x = x;
}public double getY() {
return y;
}public void setY(double y) {
this.y = y;
}
}

class Figure{
enum Shape{RECTANGLE,CIRCLE}final Shape shape;double length;
shape = Shape.CIRCLE;
}Figure(double length,double width){
shape = Shape.RECTANGLE;
this.length = length;
this.width = width;
}double area(){
switch (shape){
case RECTANGLE:
return length * width;
case CIRCLE:
default:
throw new AssertionError();
}
}
}

abstract class Figure{abstract double area();
}class Circle extends Figure{
}class Rectangle extends Figure{
final double length;
final double width;Rectangle(double length,double width){
this.length = length;
this.width = width;
}double area(){ return length * width;}
}

public interface ObjectStreamConstants {/**
* Magic number that is written to the stream header.
*/
final static short STREAM_MAGIC = (short)0xaced;/**
* Version number that is written to the stream header.
*/
final static short STREAM_VERSION = 5;/* Each item in the stream is preceded by a tag
*/
}