solid / dry

25
SOLID / DRY Princípios Vinícius Tonial Sossella

Upload: vinicius-t-sossella

Post on 13-Feb-2017

32 views

Category:

Software


0 download

TRANSCRIPT

Page 1: SOLID / DRY

SOLID / DRY

Princípios

Vinícius Tonial Sossella

Page 2: SOLID / DRY

O que é?Boas práticas de programação

Page 3: SOLID / DRY

S.O.L.I.D1- Single resposability

2- Open/Closed

3- Liskov Substitution Principle

4- Interface Segregation

5- Dependency Inversion Principe

Page 4: SOLID / DRY

PRA QUE?– Melhorar a manutenção do código com menos esforço.

– Tornar o código mais fácil de entender e testar.

– Melhorar capacidade de reuso.

– Diminuir o acoplamento entre objetos.

CODE SMELLS

Page 5: SOLID / DRY

Pra qual linguagem?Qualquer linguagem pode se beneficiar destas boas práticas

Page 6: SOLID / DRY

Tá, MAS E NA PRÁTICAWhat does it mean?

Page 7: SOLID / DRY

Classes que fazem o que não deveriam fazer

TOO MUCH!

SINGLE RESPONSABILITY

Page 8: SOLID / DRY

SINGLE RESPONSABILITY

Page 9: SOLID / DRY

Classes aberta para extensões, mas fechadas para modificações

OPEN/CLOSE

Whaat?!

Page 10: SOLID / DRY

OPEN/CLOSE

Page 11: SOLID / DRY

OPEN/CLOSEOPEN/CLOSEVIOLATION

Page 12: SOLID / DRY

OPEN/CLOSE

Page 13: SOLID / DRY

liskov "Se você pode invocar um método q() de uma classe T (base), deve poder também invocar o método q() de uma classe T'(derivada) que é derivada com herança de T (base).”

Page 14: SOLID / DRY

liskov

Page 15: SOLID / DRY

liskov LISKOV

VIOLATION

QUADRADONÃO É

RETÂNGULO

Page 16: SOLID / DRY

interface segregation (SEGREGAÇÃO DE INTERFACE)Segregação?

Separação, Afastamento…

+ Small Interfaces

- Big Interfaces

Page 17: SOLID / DRY

interface segregation (SEGREGAÇÃO DE INTERFACE)

Page 18: SOLID / DRY

interface segregation (SEGREGAÇÃO DE INTERFACE)

Page 19: SOLID / DRY

interface segregation (SEGREGAÇÃO DE INTERFACE)

Page 20: SOLID / DRY

DEPENDENCY INVERSIONDESACOPLAMENTO

DI = Componentes/Classes devem depender de abstrações/interfaces

Page 21: SOLID / DRY

DEPENDENCY INVERSION

Page 22: SOLID / DRY

DEPENDENCY INVERSIONE see…. o construtor das classes de Serviços mudarem? Tpw, receberem parametros?

Page 23: SOLID / DRY

DEPENDENCY INVERSION

Dependecy Injection, é um design Pattern que prega um tipo de controle externo de instâncias "Um container, uma classe, configurações via arquivo." Frameworks...

IOC = INVERSION OF CONTROL é um pattern que prega para usarmos o controle das instâncias de uma determinada classe ser tratada externamente e não dentro da classe em questão, ou seja, Inverter o controle de uma classe delegando para uma outra classe, interface, componente, serviço, etc.

Page 24: SOLID / DRY

DRYDont Repeat YourSelfA piece of logic should only be represented once in an application.

Repetition is the root of all software evil.

Page 25: SOLID / DRY

DRYRepetition does not only refer to writing the same piece of logic twice in two different places. It also refers to repetition in your processes – testing, debugging, deployment etc. Repetition in logic is often solved by abstractions or some common service classes whereas repetition in your process is tackled by automation. A lot of tedious processes can be automated by concepts from Continuous Integration and related automation softwarE. Unit testing can be automated by testing tools such as nUnit….

DRY is known by other names as well: Once and Only Once, and Duplication is Evil (DIE).