/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package factorypatternuml;
import java.sql.Connection;
/**
*
* @author Gagah
*/
public class Factory {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
selectconnection pilih = new selectconnection("posgresql");
connection con = pilih.Getconnection();
con.createconnection();
}
}
interface connection {
public void createconnection();
}
class mysql implements connection {
@Override
public void createconnection() {
System.out.println("koneksi mysql");
}
}
class oracle implements connection {
@Override
public void createconnection() {
System.out.println("koneksi oracle");
}
}
class posgresql implements connection{
@Override
public void createconnection() {
System.out.println("koneksi posgresql");
}
}
class selectconnection {
public selectconnection(String connection) {
this.connection = connection;
}
private String connection;
public connection Getconnection() {
if (this.connection.toLowerCase().equals("mysql")) {
return new mysql();
}else if(this.connection.toLowerCase().equals("posgresql")){
return new posgresql();
}else{
return new oracle();
}
}
}