Demo entry 6763608

sdgdgdfg

   

Submitted by anonymous on Oct 24, 2018 at 05:02
Language: Java. Code size: 1.8 kB.

public class Actor {
	private String type;
	private String sex;
	private String race;
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getRace() {
		return race;
	}
	public void setRace(String race) {
		this.race = race;
	}
	
	
}

abstract class Builder {
	protected Actor actor = new Actor();
	
	public abstract void buildType();
	public abstract void buildSex();
	public abstract void buildRace();
	
	public Actor createActor() {
		return actor;
	}
}

class HeroBuilder extends Builder {
	public void buildType() {
		actor.setType("英雄");
	}
	public void buildSex() {
		actor.setSex("女");
	}
	public void buildRace() {
		actor.setRace("矮人");
	}
}

class AngleBuilder extends Builder {
	public void buildType() {
		actor.setType("天使");
	}
	public void buildSex() {
		actor.setSex("男");
	}
	public void buildRace() {
		actor.setRace("人类");
	}
}

class DevilBuilder extends Builder {
	public void buildType() {
		actor.setType("魔鬼");
	}
	public void buildSex() {
		actor.setSex("无");
	}
	public void buildRace() {
		actor.setRace("泰坦");
	}
}

class ActorController {
	public Actor construct(Builder builder) {
		Actor actor;
		builder.buildType();
		builder.buildSex();
		builder.buildRace();
		actor = builder.createActor();
		
		return actor;
	}
}

class Client {
	public static void main(String[] args) {
		Actor actor;
		ActorController act = new ActorController();
		Builder builder = new AngleBuilder();
		
		actor = act.construct(builder);
		
		System.out.println(actor.getRace());
		System.out.println(actor.getSex());
		System.out.println(actor.getType());
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).