1.内部类定义
public class innerClazz {
private String name ;
private int age;
/**
* 每个内部类独立继承实现impl
* 具有外部类访问权
*/
class InnerClass{
public InnerClass(){
name = "cxuan";
age = 25;
}
}
}
2.静态Builder模式
// 静态工厂和构造函数都可以创建对象,局限性:参数过多可读性不好
public class BuilderTest {
private String name;
private Double num;
public BuilderTest(Builder builder){
}
public static class Builder{
private String name;
private Double num;
public BuilderTest build() {
return new BuilderTest(this);
}
}
public static void main(String[] args) {
BuilderTest builderTest = new BuilderTest.Builder()
.build();
}
}