多态的扩展实例

interface Operation
{
	void insert();
	void delete();
}

class JDBC implements Operation
{
	public void insert()
	{
		System.out.println("JDBC的插入");
	}

	public void delete()
	{
		System.out.println("JDBC的删除");
	}
}

class Hebirate implements Operation
{
	public void insert()
	{
		System.out.println("Hebirate的插入");
	}
	public void delete()
	{
		System.out.println("Hebirate的删除。");
	}
}

class  DataBaseOperation
{
	public static void main(String[] args) 
	{
		Operation op=new Hebirate();              //通过接口,当我们更改操作类型时候,直接Operation op=new JDBC();即可,提高扩展性
		op.insert();
		op.delete();
	}
}

posted @ 2015-01-03 10:47  静以养身 俭以养德  阅读(120)  评论(0编辑  收藏  举报