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

982 views

Published on

Programming is a journey. To achieve effective, clean, easy-to-read, and beautiful Java code, you have to practice programming every day. This session shares some lessons collected along 15 years of Java programming. It includes live code examples of how to write truly object-oriented code; when to make a type (and how to use it on JPA providers); how to properly use encapsulation and polymorphism in "ifless" programming; how to properly take advantage of the enum power; and how to use some very useful open source libraries such as Google Guava and Joda-Time to achieve clean Java code.

Session presented at JavaOne Latin America 2012.

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
982
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

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

  1. 1. Java CraftsmanshipLessons Learned on How to Produce Truly Beautiful Java Code Edson Yanaga @edsonyanaga
  2. 2. 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
  3. 3. 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
  4. 4. Software é artesanal
  5. 5. Ou não?
  6. 6. Software Craftsmanship
  7. 7. Deus?
  8. 8. Nós não precisamos de mais programadores!
  9. 9. O que você sabe/aprendeu sobre OO?
  10. 10. Herança PolimorfismoEncapsulamento
  11. 11. Encapsulamento Polimorfismo Herança
  12. 12. public class Pessoa { private String nome; private String cpf; private String telefone; private Date nascimento;}
  13. 13. Code Smells
  14. 14. Primitive Obsession
  15. 15. public class Pessoa { private String nome; private Cpf cpf; private Telefone telefone; private Date nascimento;}
  16. 16. Tell, dont’ ask
  17. 17. public class Conta { private BigDecimal saldo = new BigDecimal("0.00"); public BigDecimal getSaldo() { return saldo; } public void setSaldo(BigDecimal saldo) { this.saldo = saldo; }}
  18. 18. 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); } }
  19. 19. 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; }}
  20. 20. public class ContaService { public void somarValorNaConta(Conta conta, BigDecimal valor) { checkNotNull(conta); conta.somar(valor); } }
  21. 21. What if...
  22. 22. Null Object
  23. 23. Cuide do seu código.
  24. 24. Test-Driven Development
  25. 25. Software melhor, mundo melhor
  26. 26. Edson Yanagaedson@yanaga.com.br @edsonyanaga www.yanaga.com.br

×