0
I have a product list:
CREATE TABLE produtos (
idProduto int(2) unsigned NOT NULL AUTO_INCREMENT,
tipo enum('m','p') NOT NULL,
modelo varchar(100) NOT NULL DEFAULT '',
bandejas enum('1','2') NOT NULL DEFAULT '1',
peso int(4) DEFAULT '0',
prensagem int(4) NOT NULL DEFAULT '0',
precoUnitario int(5) NOT NULL DEFAULT '0',
comprimento int(3) NOT NULL,
largura int(3) NOT NULL,
cabo varchar(50) NOT NULL DEFAULT '',
ligacao enum('m','b') NOT NULL DEFAULT 'b',
potencia int(7) NOT NULL DEFAULT '0',
consumo int(7) NOT NULL DEFAULT '0',
corrente int(2) NOT NULL DEFAULT '0',
disjuntor int(2) NOT NULL DEFAULT '0',
descricao text NOT NULL,
estoque int(2) NOT NULL DEFAULT '0',
bloqueado char(1) NOT NULL DEFAULT '',
PRIMARY KEY (idProduto)
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8;
And the Classes Products
<?php
Class Produtos {
private $idProduto;
private $tipo;
private $modelo;
private $bandejas;
private $peso;
private $prensagem;
private $precoUnitario;
private $comprimento;
private $largura;
private $cabo;
private $ligacao;
private $potencia;
private $consumo;
private $corrente;
private $disjuntor;
private $descricao;
private $estoque;
private $bloqueado;
public function __construct (
$_tipo,
$_modelo,
$_bandejas,
$_peso,
$_prensagem,
$_precoUnitario,
$_comprimento,
$_largura,
$_cabo,
$_ligacao,
$_potencia,
$_consumo,
$_corrente,
$_disjuntor,
$_descricao,
$_estoque,
$_bloqueado
) {
$this->tipo = $_tipo;
$this->modelo = $_modelo;
$this->bandejas = $_bandejas;
$this->peso = $_peso;
$this->prensagem = $_prensagem;
$this->precoUnitario = $_precoUnitario;
$this->comprimento = $_comprimento;
$this->largura = $_largura;
$this->cabo = $_cabo;
$this->ligacao = $_ligacao;
$this->potencia = $_potencia;
$this->consumo = $_consumo;
$this->corrente = $_corrente;
$this->disjuntor = $_disjuntor;
$this->descricao = $_descricao;
$this->estoque = $_estoque;
$this->bloqueado = $_bloqueado;
}
////////////////////// SET'ERS //////////////////
public function setIdProduto ($_idProduto) {
$this->idProduto = $_idProduto;
}
public function getIdProduto(){
return $this->idProduto;
}
public function getTipo () {
return $this->tipo;
}
public function getModelo () {
return $this->modelo;
}
public function getBandejas(){
return $this->bandejas;
}
public function getPeso(){
return $this->peso;
}
public function getPrensagem(){
return $this->prensagem;
}
public function getPrecoUnitario(){
return $this->precoUnitario;
}
public function getComprimento(){
return $this->comprimento;
}
public function getLargura(){
return $this->largura;
}
public function getCabo(){
return $this->cabo;
}
public function getLigacao(){
return $this->ligacao;
}
public function getPotencia(){
return $this->potencia;
}
public function getConsumo(){
return $this->consumo;
}
public function getCorrente(){
return $this->corrente;
}
public function getDisjuntor(){
return $this->disjuntor;
}
public function getDescricao(){
return $this->descricao;
}
public function getEstoque(){
return $this->estoque;
}
public function getBloqueado(){
return $this->bloqueado;
}
}
At first, it would be to register only machines that have all those attributes.
However, in the end, the customer decided to sell also in the shop, accessories of these machines of the most diverse type and that logically does not have several of the attributes that the machines possess. For example we can quote sheet metal used for making machines who do not attributes type electric current, power, etc... But they have attributes like weight, price, etc...
Any OO solution that helps me not to have a general system remodeling job in order to get around this problem?
In this case, the solution is to rethink the use of OO in PHP, which is the cause of all these problems. Note that you are searching for OO, but making a typical "old-fashioned" procedural structure, which is to create calls with 2793 positional parameters all "hardcoded" in the class. To work in OO, you need to have an overview of the system, and already predict the maximum versatility BEFORE you start writing the code. The procedural suffers less from it. Note that it is not a criticism of OO, but rather the "institutionalized" misuse of the paradigm, especially in PHP.
– Bacco
Imagine if each time you have a given new variable, you need to edit the entire class to adjust? Then some other company (or a different sector) takes an interest in the system, and their products are a little different, they start having to keep two versions of the code, and from there on it only makes the situation worse. Perhaps it is the case to abstract these things while it is early. Rather a little more work now, than an unsustainable system in the future.
– Bacco
I understood. Only now the client decided to talk about it and always omitting the information when asked. I think the exit will be really remodel! Aff.
– Carlos Rocha