package com.cn.sun;
abstract class dele{
abstract void delete();
}
abstract class inse{
abstract void insert();
}
abstract class AbstractFactory{
abstract dele getDete();
abstract inse getInsert();
}
/**
* Mysql1 删除
* @author sp
*
*/
class Mysql1 extends dele{
@Override
void delete() {
System.out.println("mysql:删除");
}
}
/**
* Mysql2 插入
* @author sp
*
*/
class Mysql2 extends inse{
@Override
void insert() {
System.out.println("mysql:插入");
}
}
/**
* Mysql1 删除
* @author sp
*
*/
class oracle1 extends dele{
@Override
void delete() {
System.out.println("oracle:删除");
}
}
/**
* Mysql2 插入
* @author sp
*
*/
class oracle2 extends inse{
@Override
void insert() {
System.out.println("oracle:插入");
}
}
/**
* Mysql 工厂类
* @author sp
*
*/
class MysqlFactory extends AbstractFactory{
@Override
dele getDete() {
// TODO Auto-generated method stub
return new Mysql1();
}
@Override
inse getInsert() {
// TODO Auto-generated method stub
return new Mysql2();
}
}
/**
* Oracle 工厂类
* @author sp
*
*/
class OracleFactory extends AbstractFactory{
@Override
dele getDete() {
// TODO Auto-generated method stub
return new oracle1();
}
@Override
inse getInsert() {
// TODO Auto-generated method stub
return new oracle2();
}
}
public class AbstractFactoryAll {
public static void main(String[] args) {
AbstractFactory myFy = new MysqlFactory();
AbstractFactory OraFy = new OracleFactory();
myFy.getInsert().insert();
myFy.getDete().delete();
OraFy.getInsert().insert();
OraFy.getDete().delete();
}
abstract class dele{
abstract void delete();
}
abstract class inse{
abstract void insert();
}
abstract class AbstractFactory{
abstract dele getDete();
abstract inse getInsert();
}
/**
* Mysql1 删除
* @author sp
*
*/
class Mysql1 extends dele{
@Override
void delete() {
System.out.println("mysql:删除");
}
}
/**
* Mysql2 插入
* @author sp
*
*/
class Mysql2 extends inse{
@Override
void insert() {
System.out.println("mysql:插入");
}
}
/**
* Mysql1 删除
* @author sp
*
*/
class oracle1 extends dele{
@Override
void delete() {
System.out.println("oracle:删除");
}
}
/**
* Mysql2 插入
* @author sp
*
*/
class oracle2 extends inse{
@Override
void insert() {
System.out.println("oracle:插入");
}
}
/**
* Mysql 工厂类
* @author sp
*
*/
class MysqlFactory extends AbstractFactory{
@Override
dele getDete() {
// TODO Auto-generated method stub
return new Mysql1();
}
@Override
inse getInsert() {
// TODO Auto-generated method stub
return new Mysql2();
}
}
/**
* Oracle 工厂类
* @author sp
*
*/
class OracleFactory extends AbstractFactory{
@Override
dele getDete() {
// TODO Auto-generated method stub
return new oracle1();
}
@Override
inse getInsert() {
// TODO Auto-generated method stub
return new oracle2();
}
}
public class AbstractFactoryAll {
public static void main(String[] args) {
AbstractFactory myFy = new MysqlFactory();
AbstractFactory OraFy = new OracleFactory();
myFy.getInsert().insert();
myFy.getDete().delete();
OraFy.getInsert().insert();
OraFy.getDete().delete();
}
执行结果:
mysql:插入
mysql:删除
oracle:插入
oracle:删除
}