Download - Refatorar é preciso. Palestra TDC 2014
![Page 1: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/1.jpg)
Globalcode – Open4education
Refatorar é Preciso!
Daniel Archer
![Page 2: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/2.jpg)
Globalcode – Open4education
Quem vos fala
Daniel Archer
Formado em Análise de Sistemas
Programador PHP há 5 anos
E eu também escrevo código Ruim...
![Page 3: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/3.jpg)
Globalcode – Open4education
Quem aqui escreve um bom código?
![Page 4: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/4.jpg)
Globalcode – Open4education
Refactoring
Refactoring: a change made to the internal structure of software to make it easier to understand and cheaper to
modify without changing its observable behavior.
• Martin Fowler
![Page 5: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/5.jpg)
Globalcode – Open4education
Refactoring
![Page 6: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/6.jpg)
Globalcode – Open4education
Problemas Enfrentados
Dificuldade de Entendimento
Alto acoplamento
Manutenção perigosa
Produtividade reduzida
![Page 7: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/7.jpg)
Globalcode – Open4education
Ferramentas
Clean Code
Object Calisthenics
Princípios SOLID
Design Patterns
![Page 8: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/8.jpg)
Globalcode – Open4education
Conceitos Básicos
Clean Code
Clean code can be read, and enhanced by a
developer other than its original author. (Dave A. Thomas, OTI Founder)
Clean code is simple and direct(Grady Booch, author of Object Oriented Analysis and Design with Applications)
![Page 9: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/9.jpg)
Globalcode – Open4education
![Page 10: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/10.jpg)
Globalcode – Open4education
Conceitos Básicos
Object Calisthenic
Um nível de indentação por método
Não utilize else
Encapsule os tipos primitivos
Apenas um -> por linha
Não Abrevie
Mantenha suas classes Pequenas
Limite o número de atributos (2~5)
Utilize coleções
Use Getters e Setters
![Page 11: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/11.jpg)
Globalcode – Open4education
Conceitos Básicos
Princípios SOLID
S ingle Responsability
O pen / Closed
L iskov Subtitution
I nterface Segregation
D ependency Injection
![Page 12: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/12.jpg)
Globalcode – Open4education
Vamos ver na prática...
Como identificar e tomar a melhor decisão.
![Page 13: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/13.jpg)
Globalcode – Open4education
Refatoração - Interna
Mantenha a mesma interface
Sinalize métodos depreciados
Teste
![Page 14: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/14.jpg)
Globalcode – Open4education
![Page 15: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/15.jpg)
Globalcode – Open4education
![Page 16: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/16.jpg)
Globalcode – Open4education
Refatoração - Estruturada
Nem sempre teremos um código minimamente orientado a objetos
Mapeie as relaçõesProcure por dependências desta página em outros arquivos
Agrupe as Classes em Namespaces ou Pastas (v.5.2-)
![Page 17: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/17.jpg)
Globalcode – Open4education
![Page 18: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/18.jpg)
Globalcode – Open4education
![Page 19: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/19.jpg)
Globalcode – Open4education
Refatoração - Diretórios
Defina qual o objetivo final
Documente o que for alterado
Altere apenas o necessário
Não tenha pressa
Defina Etapas
![Page 20: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/20.jpg)
Globalcode – Open4education
![Page 21: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/21.jpg)
Globalcode – Open4education
![Page 22: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/22.jpg)
Globalcode – Open4education
![Page 23: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/23.jpg)
Globalcode – Open4education
Refatoração - Objetos
Inicie pelos métodos de menor complexidade
Informe a equipe sobre a mudança na interface de alguma classe.
Siga os padrões especificados
Dica de ouro: converse com a sua equipe antes.
![Page 24: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/24.jpg)
Globalcode – Open4education
Ouça as opiniões
Mesmo dentro de um grupo de desenvolvedores, dependemos da aceitação da equipe para que as mudanças sejam bem sucedidas.
![Page 25: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/25.jpg)
Globalcode – Open4education
![Page 26: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/26.jpg)
Globalcode – Open4education
![Page 27: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/27.jpg)
Globalcode – Open4education
Esqueça o padrão Singleton
A maior parte das atuais atribuições do padrão singletonestá relacionada a problemas no design
![Page 28: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/28.jpg)
Globalcode – Open4education
![Page 29: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/29.jpg)
Globalcode – Open4education
![Page 30: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/30.jpg)
Globalcode – Open4education
Acredite em outras ferramentas.Reuse!
Não tente reinventar a roda
![Page 31: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/31.jpg)
Globalcode – Open4education
![Page 32: Refatorar é preciso. Palestra TDC 2014](https://reader034.vdocuments.pub/reader034/viewer/2022042614/5594281a1a28ab07418b45e8/html5/thumbnails/32.jpg)
Globalcode – Open4education