SOLID / DRY
-
Upload
vinicius-t-sossella -
Category
Software
-
view
32 -
download
0
Transcript of SOLID / DRY
SOLID / DRY
Princípios
Vinícius Tonial Sossella
O que é?Boas práticas de programação
S.O.L.I.D1- Single resposability
2- Open/Closed
3- Liskov Substitution Principle
4- Interface Segregation
5- Dependency Inversion Principe
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
Pra qual linguagem?Qualquer linguagem pode se beneficiar destas boas práticas
Tá, MAS E NA PRÁTICAWhat does it mean?
Classes que fazem o que não deveriam fazer
TOO MUCH!
SINGLE RESPONSABILITY
SINGLE RESPONSABILITY
Classes aberta para extensões, mas fechadas para modificações
OPEN/CLOSE
Whaat?!
OPEN/CLOSE
OPEN/CLOSEOPEN/CLOSEVIOLATION
OPEN/CLOSE
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).”
liskov
liskov LISKOV
VIOLATION
QUADRADONÃO É
RETÂNGULO
interface segregation (SEGREGAÇÃO DE INTERFACE)Segregação?
Separação, Afastamento…
+ Small Interfaces
- Big Interfaces
interface segregation (SEGREGAÇÃO DE INTERFACE)
interface segregation (SEGREGAÇÃO DE INTERFACE)
interface segregation (SEGREGAÇÃO DE INTERFACE)
DEPENDENCY INVERSIONDESACOPLAMENTO
DI = Componentes/Classes devem depender de abstrações/interfaces
DEPENDENCY INVERSION
DEPENDENCY INVERSIONE see…. o construtor das classes de Serviços mudarem? Tpw, receberem parametros?
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.
DRYDont Repeat YourSelfA piece of logic should only be represented once in an application.
Repetition is the root of all software evil.
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).