码迷,mamicode.com
首页 > 编程语言 > 详细

java设计模式_抽象工厂

时间:2014-09-26 20:52:08      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   os   ar   java   sp   2014   art   

bubuko.com,布布扣

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: DatabaseFactory.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午12:03:46 
 * @version V1.0
 */
public interface DatabaseFactory {
    
    public User createUser();
    public Department createDepartment();

}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: OracleFactory.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午2:15:54 
 * @version V1.0
 */
public class OracleFactory implements DatabaseFactory {

    @Override
    public User createUser() {
        return new OracleUserImp();
    }

    @Override
    public Department createDepartment() {
        return new OracleDepartmentImp();
    }

}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: SqlServerFactory.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午2:15:35 
 * @version V1.0
 */
public class SqlServerFactory implements DatabaseFactory {

    @Override
    public User createUser() {
        return new SqlServerUserImp();
    }

    @Override
    public Department createDepartment() {
        return new SqlServerDepartmentImp();
    }

}


package com.wangbiao.design.abstractfactory;

/**
 * 
 * @Title: User.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午12:04:25 
 * @version V1.0
 */
public interface User {
    public void insertUser();
    public void selectUser();
}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

import com.wangbiao.design.abstractfactory.User;

/**
 * @Title: SqlServerUserImp.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午2:02:29 
 * @version V1.0
 */
public class SqlServerUserImp implements User {

    @Override
    public void insertUser() {
        System.out.println("insert User using Sql Server ");
        
    }

    @Override
    public void selectUser() {
        System.out.println("select User using Sql Server ");
    }


}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

import com.wangbiao.design.abstractfactory.User;

/**
 * @Title: OracleUserImp.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午2:02:49 
 * @version V1.0
 */
public class OracleUserImp implements User {

    @Override
    public void insertUser() {
        System.out.println("insert User using Oracle ");
    }

    @Override
    public void selectUser() {
        System.out.println("select User using Oracle ");        
    }


}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: Department.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午12:04:19 
 * @version V1.0
 */
public interface  Department {
    public void insertDepartment();
    public void selectDepartment();
}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: OracleDepartmentImp.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午2:04:50 
 * @version V1.0
 */
public class OracleDepartmentImp implements Department {

    @Override
    public void insertDepartment() {
        System.out.println("insert Department using Oracle ");            
    }

    @Override
    public void selectDepartment() {
        System.out.println("select Department using Oracle ");            
    }

}

/**
 * 
 */
package com.wangbiao.design.abstractfactory;

/**
 * @Title: Client.java
 * @Package com.wangbiao.design.abstractfactory
 * @Description: TODO 
 * @author wangbiao   
 * @date 2014-9-26 下午12:03:00 
 * @version V1.0
 */
public class Client {

    public static void main(String[] args) {
        
        
        DatabaseFactory factory_oracel = new OracleFactory();
        User user_oracel = factory_oracel.createUser();
        Department depart_oracle = factory_oracel.createDepartment();
        
        user_oracel.insertUser();
        user_oracel.selectUser();
        depart_oracle.insertDepartment();
        depart_oracle.selectDepartment();
        
        
        DatabaseFactory factory_sqlserver = new SqlServerFactory();
        User user_sqlserver = factory_sqlserver.createUser();
        Department depart_sqlserver = factory_sqlserver.createDepartment();
        
        user_sqlserver.insertUser();
        user_sqlserver.selectUser();
        depart_sqlserver.insertDepartment();
        depart_sqlserver.selectDepartment();
        
    }

}


java设计模式_抽象工厂

标签:des   http   io   os   ar   java   sp   2014   art   

原文地址:http://my.oschina.net/u/617909/blog/318987

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!