-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractFactory2.php
More file actions
67 lines (58 loc) · 1.4 KB
/
abstractFactory2.php
File metadata and controls
67 lines (58 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
abstract class AbstractDatabase {
abstract function getConnection();
}
abstract class AbstractDatabaseFactory {
abstract function create();
}
class MySQLServer extends AbstractDatabase {
function getConnection(){
echo "MySQL Connection\n";
}
}
class PostgreSQLServer extends AbstractDatabase {
function getConnection(){
echo "PostgreSQL Connection\n";
}
}
class MSSQLServer extends AbstractDatabase {
function getConnection(){
echo "MSSQL Connection\n";
}
}
class MySQLFactory extends AbstractDatabaseFactory{
function create(){
return new MySQLServer();
}
}
class PostgreSQLFactory extends AbstractDatabaseFactory{
function create(){
return new PostgreSQLServer();
}
}
class MSSQLFactory extends AbstractDatabaseFactory{
function create(){
return new MSSQLServer();
}
}
class DatabaseFactory {
function getMySQL(){
return new MySQLFactory();
}
function getPostgreSQL(){
return new PostgreSQLFactory();
}
function getMSSQL(){
return new MSSQLFactory();
}
}
$df = new DatabaseFactory();
$mysqlF = $df->getMySQL();
$mysql = $mysqlF->create();
echo $mysql->getConnection();
$postgreSqlF = $df->getPostgreSQL();
$postgresql = $postgreSqlF->create();
echo $postgresql->getConnection();
$mssqlF = $df->getMSSQL();
$mssql = $mssqlF->create();
echo $mssql->getConnection();