Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package factorypatternuml;
  6.  
  7. import java.sql.Connection;
  8.  
  9. /**
  10.  *
  11.  * @author Gagah
  12.  */
  13. public class Factory {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         // TODO code application logic here
  20.         selectconnection pilih = new selectconnection("posgresql");
  21.         connection con = pilih.Getconnection();
  22.         con.createconnection();
  23.     }
  24. }
  25.  
  26. interface connection {
  27.  
  28.     public void createconnection();
  29. }
  30.  
  31. class mysql implements connection {
  32.  
  33.     @Override
  34.     public void createconnection() {
  35.         System.out.println("koneksi mysql");
  36.     }
  37. }
  38.  
  39. class oracle implements connection {
  40.  
  41.     @Override
  42.     public void createconnection() {
  43.         System.out.println("koneksi oracle");
  44.     }
  45. }
  46.  
  47. class posgresql implements connection{
  48.  
  49.     @Override
  50.     public void createconnection() {
  51.         System.out.println("koneksi posgresql");
  52.     }
  53.  
  54. }
  55.  
  56. class selectconnection {
  57.  
  58.     public selectconnection(String connection) {
  59.         this.connection = connection;
  60.     }
  61.     private String connection;
  62.  
  63.     public connection Getconnection() {
  64.         if (this.connection.toLowerCase().equals("mysql")) {
  65.             return new mysql();
  66.         }else if(this.connection.toLowerCase().equals("posgresql")){
  67.         return new posgresql();
  68.         }else{
  69.         return new oracle();
  70.         }
  71.     }
  72. }