How to split the addressing of a class in PHP?

0

What is the best way to split this Aluno ?

<?php
    class Aluno{
        private $nome;
        private $sobrenome;
        private $email;
        private $telefone;
        private $cep;
        private $rua;
        private $endereco;
        private $numero;
        private $logradouro;
        private $cidade;
        private $estado;
        private $usuario;
        private $senha;

        public function getNome(){
            return $this->nome;
        }
        public function setNome($nome){
            $this->nome = $nome;
        }

        public function getSobrenome(){
            return $this->sobrenome;
        }
        public function setSobrenome($sobrenome){
            $this->sobrenome = $sobrenome;
        }

        public function getEmail(){
            return $this->email;
        }
        public function setEmail($email){
            $this->email = $email;
        }


        public function getTelefone(){
            return $this->telefone;
        }
        public function setTelefone($telefone){
            $this->telefone = $telefone;
        }

        public function getCep(){
            return $this->cep;
        }
        public function setCep($cep){
            $this->cep = $cep;
        }

        public function getRua(){
            return $this->rua;
        }
        public function setRua($rua){
            $this->rua = $rua;
        }

        public function getEndereco(){
            return $this->endereco;
        }

        public function setEndereco($endereco){
            $this->endereco = $endereco;
        }

        public function getNumero(){
            return $this->numero;
        }
        public function setNumero($numero){
            $this->numero = $numero;
        }

        public function getLogradouro(){
            return $this->logradouro;
        }
        public function setLogradouro($lougradouro){
            $this->lougradouro = $logradouro;
        }


        public function getCidade(){
            return $this->cidade;
        }
        public function setCidade($cidade){
            $this->cidade = $cidade;
        }


        public function getEstado(){
            return $this->estado;
        }
        public function setEstado($estado){
            $this->estado = $estado;
        }

        public function getUsuario(){
            return $this->usuario;
        }

        public function setUsuario($usuario){
            $this->usuario = $usuario;
        }

        public function getSenha(){
            return $this->senha;
        }

        public function setSenha($senha){
            $this->senha = $senha;
        }



    }
?>

Would it be relevant to separate some information in another class as a database table? Type:

Class Telefone{
       private $ddd;
       private $numero;

      public function getDDD(){
        return $this->ddd;
      }
      public function setDDD($ddd){
        $this->ddd = $ddd;
      }
      public function getTelefone(){
        return $this->telefone;
      }
      public function setTelefone($telefone){
        $this->telefone = $telefone;
      }

I need to apply these classes and methods in the state (% with% get and set state), city ( Class Estado get and set city), address ( Class Cidade containing number, cep, complement, lougradouro getters and setters etc).

Would this also apply with Class Endereço and password create a class just for both?

Example:

Class Estado{
       private $estado;

          public function getEstado(){
            return $this->estado;
          }
          public function setEstado($estado){
            $this->estado = $estado;
          }
}

Class Cidade{
       private $cidade

       public function getCidade(){
         return $this->cidade;
       }
       public function setCidade($cidade){
         $this->cidade = $cidade;
} 

Etc.

NOTE: When I model something like this, do you have any specific techniques to separate correctly or depend on the programmer?

    
asked by anonymous 12.12.2018 / 18:25

1 answer

2

They have commented but I want to strengthen. You are programming as if you were in Java. In PHP you usually do not need any of this. PHP is a script language, it was created to make simple code and people started creating complex, and by the way, unnecessary code. In general, they do not know why they are doing it, they only do it because they have seen someone doing something, without understanding the reality and context of who did it. Probably this person did for the same reason you did so only because you saw someone else doing it. It is a joke of Macaco Simão that has nothing to do with engineering, which is our professional area.

Another problem with the question is wanting to know the best form of random people on the internet who do not know your problem. Or worse yet your problem may be artificial. People find that making artificial problems teach software development, but does not teach, at most teaches use a language mechanism, which is not the case the question, she wants to know about organization of data structure, which is only useful when you know 100% of requirements and correctly. We do not know.

Aside from this, as everyone is accustomed to doing, I would delete everything and start in a totally different and simple way.

Only you know if it would be relevant to separate into parts. Can you justify that? Will there be gain? Does it serve any purpose? Do not you have a better way to do this? For what you have demonstrated you do not need to, but it may just be that you have proven wrong for us, if you have done so any attempt to help will be wrong.

Modeling a data structure depends essentially on the current requirements and the possibility of future requirements. Modeling is experience. It takes real, detailed cases and see if it works over time and learn from mistakes, or even use other people's experience to show where errors are, provided you have all the information you need. Modeling has to do with logical thinking by tailoring. It is to understand things that are not even computing.

The answers to the comments show that you are stuck with a vision of doing things. That's why I hate the way people put things on the internet, they ruin people's minds forever. The person can no longer see another way of doing it, everything turns out to be a meaningless cake recipe.

There are controversies about what the classes are, but in general they are the opposite of database tables, even though they look the same. I even wanted them to be used in a similar way, but that's not how people use it, but the subject is too broad to discuss here. Anyway this case seems to be separating the individual data into separate tables, this seems very wrong, but it may be just because there are no clear requirements in the question.

    
17.12.2018 / 12:26