-
Notifications
You must be signed in to change notification settings - Fork 0
/
design_patterns.html
71 lines (60 loc) · 2.29 KB
/
design_patterns.html
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
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menukaarten-docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/stylesheet.css" media="screen,print">
<link rel="stylesheet" href="assets/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="assets/css/shCore.css" media="screen,print">
<link rel="stylesheet" type="text/css" href="assets/css/shThemeDefault.css" media="screen,print">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/SyntaxHighlighter.js"></script>
<script type="text/javascript" src="assets/js/build_menu.js"></script>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<h1>Documentation SexyFramework</h1>
<span>Created by Vincent Bremer & Douwe de Haan</span>
</div>
</div>
<div id="container">
<div id="menu-wrapper">
<div id="menu">
<h1>Table of contents</h1>
<ul></ul>
</div>
</div>
<div id="content-wrapper">
<div id="content">
<!-- START CONTENT -->
<h1>Design patterns</h1>
<h2>MVC</h2>
<p>Blabla</p>
<h2>Singleton</h2>
<p>We tried to implement a singleton design pattern and one of the best examples is using it for a database connection. In the base model we have got some function to communicate with the database. These connections to the database are made my the MySQLi object which is loaded when initializing the base model. Before using the singleton, every class created a new instance of the MySQLi object. After researching how a singleton exactly works (only one instance of an object exists), we came up with the following code:</p>
<pre class="brush: php">
class load {
private static $database;
public static function database() {
// Check if a database object already exists
if ( ! self::$database) {
// The database object does not yet exist, create a new instance
self::$database = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
}
// Return the database object
return self::$database;
}
}
// Usage:
$mysqli = load::database();
</pre>
<h2>Factory class</h2>
<p></p>
<!-- END CONTENT -->
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/SyntaxHighlighter_settings.js"></script>
</body>
</html>