Duda sobre POO
Publicado por Floker (2 intervenciones) el 25/02/2015 21:21:11
Hola:
Estoy empezando con la programación orienta a objetos y tengo una duda.
Cuál sería la forma correcta?
Estoy empezando con la programación orienta a objetos y tengo una duda.
Cuál sería la forma correcta?
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
<?php
class PageHeader {
private $texto;
private $align;
private $fontcolor;
private $bgcolor;
public function __construct($te, $al, $color, $background){
$this->texto = $te;
$this->align = $al;
$this->fontcolor = $color;
$this->bgcolor = $background;
}
public function showHeader(){
echo '<h1 style="text-align: '. $this->align .' ; color: '. $this->fontcolor .' ; background-color: '. $this->bgcolor .';">'. $this->texto .'</h1>';
}
}
// Primera opción
$header = new PageHeader('Lorem ipsum dolor sit amet....', 'center', 'black', 'yellow');
$header->showHeader();
$header = new PageHeader('Textooooo', 'right', 'white', 'blue');
$header->showHeader();
// Segunda opción
$header = new PageHeader('Lorem ipsum dolor sit amet....', 'center', 'black', 'yellow');
$header = new PageHeader('Textooooo', 'right', 'white', 'blue');
$header->showHeader();
$header->showHeader();
?>
Valora esta pregunta
0