圣者
精华
|
战斗力 鹅
|
回帖 0
注册时间 2011-4-5
|
- public class MyGirl {
- // Use keyword 'protected' so others inherit 'MyGirl'
- // can touch her field or method,
- // for example: public class HisGirlNow extends MyGirl
- protected int breast;
- protected int looks;
- protected int leg;
- protected int body;
- protected MyGirl(Builder builder) {
- this.breast = builder.breast;
- this.looks = builder.looks;
- this.leg = builder.leg;
- this.body = builder.body;
- }
- protected void doSomething() {
- // TODO:evil
- }
- public static void main(String[] args) {
- MyGirl myGirl = new MyGirl.Builder((new MyFeatures()).add("otaku").add(
- "programmer")).Breast(Breast.D_CUP).Looks(Looks.BEATIFUL)
- .Leg(Leg.THIN).Body(Body.AVERAGE).build();
- myGirl.doSomething();
- }
- public static class Builder {
- private int breast = Breast.A_CUP;
- private int looks = Looks.UGLY;
- private int leg = Leg.FAT;
- private int body = Body.FAT;
- private MyFeatures myFeatures;
- public Builder(MyFeatures myFeatures) {
- this.myFeatures = myFeatures;
- }
- public MyGirl build() {
- if (this.myFeatures.contains("otaku")
- || this.myFeatures.contains("programmer")) {
- if (this.breast > Breast.A_CUP || this.looks > Looks.AVERAGE
- || this.leg < Leg.FAT || this.body < Body.FAT) {
- throw new Error("This not science!");
- }
- }
- return new MyGirl(this);
- }
- public Builder Breast(int breast) {
- this.breast = breast;
- return this;
- }
- public Builder Looks(int looks) {
- this.looks = looks;
- return this;
- }
- public Builder Leg(int leg) {
- this.leg = leg;
- return this;
- }
- public Builder Body(int body) {
- this.body = body;
- return this;
- }
- }
- }
复制代码 |
|