SlideShare uma empresa Scribd logo
Qualidade de Código
Além do Clean Code
Kete Martins Rufino - CEJS Test Case - 2017
Porque é importante?
- Difícil de manter
- Desmotivação
- Baixa produtividade
- Entregas lentas
- Mais Bugs
- Menos confiança
Tempo gasto
Leitura
10
Escrita
1
X
"Nunca julgue alguém com
prazo apertado"
Milfont, C
"O CÓDIGO É O PROJETO"
ORIENTAÇÃO A OBJETOS
O.O
- CLASSES
- OBJETOS
- HERANÇA
- COMPOSIÇÃO
- MÉTODOS
- TIPOS DE DADOS
- ENCAPSULAMENTO
- POLIMORFISMO
ABSTRAÇÃO
REUSO
EVITAR DUPLICAÇÃO
COESÃO
RESPONSABILIDADE DEPENDÊNCIA
ACOPLAMENTO
COESÃO
ACOPLAMENTO
COESÃO
ACOPLAMENTO
COESÃO
ACOPLAMENTO
COESÃO
ACOPLAMENTO
SOLID
S : Single responsibility principle (Princípio da Responsabilidade Única)
O : Open/closed principle (Princípio do Aberto/Fechado)
L : Liskov substitution principle (Princípio da Substituição de Liskov)
I : Interface segregation principle (Princípio da Segregação das Interfaces)
D : Dependency inversion principle (Princípio da Inversão de Dependência)
COESÃO
Uma classe deve ter uma ÚNICA Responsabilidade
Muitas interfaces específicas são melhores do que uma interface
geral
S : Single responsibility principle (Princípio da Responsabilidade Única)
I : Interface segregation principle (Princípio da Segregação das Interfaces)
Classes devem ser substituíveis por suas classes base.
L : Liskov substitution principle (Princípio da Substituição de Liskov)
Uma classe deve estar aberta para extensão e fechada para
modificação
O : Open/closed principle (Princípio do Aberto/Fechado)
O.O
Dependa de uma abstração e não de uma implementação.
D : Dependency inversion principle (Princípio da Inversão de Dependência)
ACOPLAMENTO
GANG OF FOUR (GoF)
1994
CATÁLOGO SOLUÇÕES
23 PADRÕES
2 CLASSIFICAÇÕES:
- PROPÓSITO
- ESCOPO
Problema
● Bebidas
○ Cachaça
○ Rum
○ Vodka
○ Tequila
● Adicionais
○ Limão
○ Refrigerante
○ Suco
○ Leite condensado
○ Gelo
○ Açúcar
Cliente vende coquetéis. O preço varia de acordo com os
ingredientes .
Problema
● Bebidas
○ Cachaça
○ Rum
○ Vodka
○ Tequila
● Adicionais
○ Limão
○ Refrigerante
○ Sal
○ Leite condensado
○ Gelo
○ Açúcar
Cliente vende coquetéis. O preço varia de acordo com os
ingredientes .
● Podem surgir
combinações novas a
qualquer momento
● Podem surgir adicionais
novos a qualquer
momento
Problema
● O preço é calculado pelas
combinações
● Princípio do
Aberto/Fechado
Solução - Decorator
Os requisitos
foram
surgindo…..
REFATORAÇÃO
Arrumar a casa, sem perder funcionalidades
Como?
1. Identificar um BAD SMELL (mal cheiro)
2. Aplicar uma técnica de refatoração
3. Testar
Bad Smells
1. Código duplicado
2. Método longo
3. Classes grandes
4. Lista de parâmetros longa
5. Inveja de dados
6. Comandos Switch
7. Classe ociosa
8. ...
1999
MARTIN FOWLER
CATÁLOGO DE TÉCNICAS
MELHORAR O QUE JÁ EXISTE
Técnicas/Ferramentas
1. Extrair método
2. Subir método na
hierarquia
3. Decompor condicional
4. Extrair Classe
5. Substituir parâmetro por
método
6. Mover método
7. Internalizar classe
8. ….
Extrair método
Testes unitários
● Mais confiança
● Documentam
● Garantem qualidade
● Exigem baixo
acoplamento ● TDD: não deixe pra fazer o
teste depois
E o Clean Code?
2008
ROBERT C. MARTIN
SIMPLICIDADE
Facilidade de Leitura
Elegância
Capítulo 1 - Conscientização
Capítulo 2 a 6 - Detalhes
Nomes Significativos
Funções
Comentários
Formatação
Objetos e Estruturas de dados
Capítulos
7. Tratamento de Erros
- Exceções no lugar de
códigos
- Não use exceções
genéricas
- Não retorne null
- Não passe null
8. Limites
- Trabalhando com código
de terceiros
- O que testar/esperar
- Evitar acoplar o código
com o de 3ºs
10 - 12. Princípio da
Responsabilidade Única
- Classes pequenas
- Coesão
- Padrões de projeto
- Java
Capítulos
9. Testes unitários
- TDD
- Testes limpos
- Um assert por teste
Capítulos
13. Concorrência
- Princípio da
Responsabilidade Única
- Testes
14 - 16. Estudos de caso
- Exemplos bons e ruins
17. Odores e Heuristicas
- Maus cheiros
- Técnicas
- Testes
Ou seja…. Ele junta tudo com
exemplos práticos
Orientação a
Objetos
Padrões de
Projeto
Técnicas de
Refatoração
Principios
de Design
Alta Coesão
Baixo
Acoplamento
Nomear coisas
Testes
Responsabilidade
única
OBRIGADA!
Referências
● Clean Code: Clean Code: A Handbook of Agile Software Craftsmanship
● https://www.infoq.com/br/articles/clean-code-book-review
● https://brizeno.wordpress.com/category/padroes-de-projeto/decorator/

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Destaque (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Qualidade de código