模板模式

Template.java
public abstract class Template
{
	public void fitment(){
		decorate();
		floor();
		paint();
	}

	public abstract void floor();

	public abstract void paint();

	public abstract void decorate();
};


Team1.java
public class Team1 extends Template
{
	public void floor(){
		System.out.println("Team1-----floor");
	}

	public void decorate(){
		System.out.println("Team1-----decorate");
	}

	public void paint(){
		System.out.println("Team1-----paint");
	}
};


Team2.java
public class Team2 extends Template
{
	public void floor(){
		System.out.println("Team2-----floor");
	}

	public void decorate(){
		System.out.println("Team2-----decorate");
	}

	public void paint(){
		System.out.println("Team2-----paint");
	}
};


Main.java
public class Main
{
	public static void main(String[] args){
		Template t = new Team1();
		t.fitment();
		Template t2 = new Team2();
		t2.fitment();
	}
};

你可能感兴趣的:(java)