-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathing.global.patrones-diseno.php
More file actions
executable file
·130 lines (95 loc) · 3.47 KB
/
Copy pathing.global.patrones-diseno.php
File metadata and controls
executable file
·130 lines (95 loc) · 3.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
Plugin Name: 00.5 - Ingenia global - Patrones de diseño
Plugin URI: http://www.ingeniaglobal.cl
Description: Ejemplo de patrones de diseño.
Version: 1.0
Author: Ingenieria e integración avanzada S.A. (Ingenia)
Author URI: http://www.ingeniaglobal.cl
License: GPL2
*/
/* Copyright 2013 Ingenieria e integrqación avanzada S.A. (Ingenia) (email : info@ingenia.es)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
use Prueba\Miguelito as Miguelito;
use Factory\Factory as Factory;
use Singlenton\DatabaseConnection as DatabaseConnection;
use Observer\UserList as UserList;
use Observer\UserListLogger as UserListLogger;
use Registry\Registry as Registry;
use Decorator\BlackCoffee as BlackCoffee;
use Decorator\WithCream as WithCream;
use Decorator\WithMilk as WithMilk;
use Decorator\WithChocolate as WithChocolate;
use ChainOfCommand\CommandChain as CommandChain;
use ChainOfCommand\MailCommand as MailCommand;
use ChainOfCommand\UserCommand as UserCommand;
use Facade\PageFacade as PageFacade;
use Polymorphism\PolymorphismExample as PolymorphismExample;
use Strategy\Cliente as Cliente;
use Strategy\ContadorDecrementa as ContadorDecrementa;
use Strategy\ContadorIncrementa as ContadorIncrementa;
require_once plugin_dir_path( __FILE__ )."loader.php";
try{
// carga de clase de ejemplo
$p = new Miguelito(); // --> este funciona
$p = Miguelito::getNombre(); // -->este funciona
// Patrón Factory
$class = "User";
$namespace = 'Factory';
$factory = Factory::create($namespace."\\".$class); // este funciona
echo "###".$factory->getName()."###";
// Patron Singlenton
$singlenton = DatabaseConnection::getInstance();
echo "@".$singlenton->getManejador()."@";
// Patron Observer
$ul = new UserList();
$ul->addObserver( new UserListLogger('A') );
$ul->addObserver( new UserListLogger('B') );
$ul->addCustomer( "Jack" );
//Registry
$item = 'Here is a registered variable';
Registry::add('variable', $item);
if (Registry::exists('variable')) {
echo '<p>"variable" exists</p>';
} else {
echo '<p>"variable" does not exists</p>';
}
//removes "Variable"
Registry::remove('variable');
// decorator
$coffee = new WithChocolate(new WithMilk(new WithCream(new BlackCoffee())));
echo 'El precio del cafe es: $' . $coffee->getBaseCost();
// command patter
$cc = new CommandChain();
$cc->addCommand( new UserCommand() );
$cc->addCommand( new MailCommand() );
$cc->runCommand( 'addUser', null );
$cc->runCommand( 'mail', null );
//Strategy
$cliente = new Cliente();
$cliente->setContador(new ContadorIncrementa());
$cliente->cuenta();
echo '<br />';
$cliente->setContador(new ContadorDecrementa());
$cliente->cuenta();
// Facade
$page = new PageFacade();
$id = 23;
$page->createAndServer($id,"Creting a page for ID {$id}.");
//PolymorphismExample
$object = new PolymorphismExample();
$object->example();
}catch( Exception $e ){
echo $e->getMessage();
}
?>