Java Craftsmanship Lessons Learned on How to Produce Truly Beautiful Java Code Edson Yanaga @edsonyanaga
Edson Yanaga • Bacharel em Ciência da Computação/UEM • Mestre em Engenharia Elétrica/UTFPR • Desenvolvedor Java desde 1997 • Administrador Unix desde 1999 • Instrutor Líder da GlobalCode desde 2012
Certificações • Oracle Certified Professional, Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer • Sun Certified Enterprise Architect for the Java Platform,Enterprise Edition 5 (i) • Certified ScrumMaster • Sun Certified Developer for Java Web Services 5 • Sun Certified Specialist for NetBeans IDE • Sun Certified Web Component Developer for J2EE 1.4 • Sun Certified Programmer for Java 2 Platform 1.4
Software é artesanal
Ou não?
Software Craftsmanship
Deus?
Nós não precisamos de mais programadores!
O que você sabe/ aprendeu sobre OO?
Herança Polimorfismo Encapsulamento
Encapsulamento Polimorfismo Herança
public class Pessoa { private String nome; private String cpf; private String telefone; private Date nascimento; }
Code Smells
Primitive Obsession
public class Pessoa { private String nome; private Cpf cpf; private Telefone telefone; private Date nascimento; }
Tell, dont’ ask
public class Conta { private BigDecimal saldo = new BigDecimal("0.00"); public BigDecimal getSaldo() { return saldo; } public void setSaldo(BigDecimal saldo) { this.saldo = saldo; } }
public class ContaService { public void somar(Conta conta, BigDecimal valor) { if (conta == null) { throw new IllegalArgumentException("Conta não pode ser nula!"); } if (valor == null) { throw new IllegalArgumentException("Valor não pode ser nulo!"); } BigDecimal saldo = conta.getSaldo(); if (saldo == null) { saldo = new BigDecimal("0.00"); } saldo = saldo.add(valor); conta.setSaldo(saldo); } }
public class Conta { private BigDecimal saldo = new BigDecimal("0.00"); public BigDecimal getSaldo() { return saldo; } public Conta somar(BigDecimal valor) { checkNotNull(valor); saldo = saldo.add(valor); return this; } }
public class ContaService { public void somarValorNaConta(Conta conta, BigDecimal valor) { checkNotNull(conta); conta.somar(valor); } }
What if...
Null Object
Cuide do seu código.
Test-Driven Development
Software melhor, mundo melhor
Edson Yanaga edson@yanaga.com.br @edsonyanaga www.yanaga.com.br
Java Craftsmanship: Lessons Learned on How to Produce Truly Beautiful Java Code

Java Craftsmanship: Lessons Learned on How to Produce Truly Beautiful Java Code