25
Boas práticas para melhor codificação Object calisthenics

Object calisthenics

Embed Size (px)

Citation preview

Page 1: Object calisthenics

Boas práticas para melhor codificaçãoObject calisthenics

Page 2: Object calisthenics

Vanderlei Alves da Silva

Analista de sistemas

https://github.com/vanderleisilva

https://www.linkedin.com/in/vanderlei-alves-da-silva-73380120

vanderleisilva.github.io

Page 3: Object calisthenics

Prefeitura de Santos

Page 4: Object calisthenics

Codificação

Computadores são estupidos;

Seguem instruções exatas;

Sem julgamento moral;

Page 5: Object calisthenics

ObjetivoMaintainability;

Readability;

Testability;

Comprehensibility;

Tonifique seu código!

Clean code

Page 6: Object calisthenics

STUPID to SOLIDSingleton

Tight Coupling

Untestability

Premature Optimization

Indescriptive Naming

Duplication

Single Responsibility Principle

Open/Closed Principle

Liskov Substitution Principle

Interface Segregation Principle

Dependency Inversion Principle

Page 7: Object calisthenics

OrigemLivro: The ThoughtWorks Anthology (Jeff Bay)

https://www.thoughtworks.com/

Page 8: Object calisthenics

O que é?

Page 9: Object calisthenics

AplicaçãoIndependente de tecnologia;

Boas práticas;

Dependente do paradigma orientado a objetos

Page 10: Object calisthenics

9 regras1. Only One Level Of Indentation Per Method2. Don't Use The ELSE Keyword3. Wrap All Primitives And Strings4. One Dot Per Line5. Don't Abbreviate6. Keep All Entities Small7. No Classes With More Than Two Instance Variables8. First Class Collections9. No Getters/Setters/Properties

Page 11: Object calisthenics

Only One Level Of Indentation Per Method

Page 12: Object calisthenics

Only One Level Of Indentation Per Method

Page 13: Object calisthenics

Don't Use The ELSE Keyword

Defensive Programming

Early returns

Page 14: Object calisthenics

Wrap All Primitives And StringsEncapsulate all the primitives within objects.

If the variable of your primitive type has a behavior, you MUST encapsulate it. And this is especially true for Domain Driven Design. DDD describes Value Objects like Money, or Hour for instance.

Domain-driven Design Primitive Obsession

Page 15: Object calisthenics

One Dot Per LineOnly talk to your immediate friends.

a.getB().getC().doSomething()

Law Of Demeter

High Cohesion

Page 16: Object calisthenics

Don't AbbreviatePor que abreviar?

Nome muito grande;

Repetido várias vezes;

Golden Rule is: if you're not able to find a name for a class, then ask yourself if this class makes sense, or if you can decouple things a bit more.

Nomes não devem exceder 2 palavras Readability

Page 17: Object calisthenics

Keep All Entities SmallNo class over 50 lines and no package over 10 files.

The idea behind this rule is that long files are harder to read, harder to understand, and harder to maintain.

Page 18: Object calisthenics

No Classes With More Than Two Instance Variables

Two is an arbitrary choice that forces you to decouple your classes a lot.

Page 19: Object calisthenics

First Class CollectionsExtensão da regra Wrap All Primitives And Strings;

Qualquer classe que contenha um array não deve conter outras propriedades;

Page 20: Object calisthenics

No Getters/Setters/Properties

It is okay to use accessors to get the state of an object, as long as you don't use the result to make decisions outside the object.

Page 21: Object calisthenics

Para terminar ...Tudo questão de organização;

Nosso pior inimigo é nós mesmos a 3 meses atrás

Page 22: Object calisthenics

Indo alémSOLID principles;

Design Patterns;

Software AntiPatterns;

Clean Code

Page 23: Object calisthenics

Perguntas!?

Page 24: Object calisthenics

Até a proxima!!!

Page 25: Object calisthenics

Bibliografiahttp://williamdurand.fr/2013/06/03/object-calisthenics/

http://martinfowler.com/books/refactoring.html

http://swreflections.blogspot.com.br/2012/03/defensive-programming-being-just-enough.html

https://sourcemaking.com/refactoring/smells/primitive-obsession

http://www.codeproject.com/Articles/339725/Domain-Driven-Design-Clear-Your-Concepts-Before-Yo

http://www.bennadel.com/blog/2375-object-calisthenics-in-javascript---my-first-attempt.htm

http://symfony.com/doc/current/contributing/code/standards.html

http://c2.com/cgi/wiki?LawOfDemeter

http://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/