46
Orientação a Objetos Princípios e Padrões

OOP: Princípios e Padroes

Embed Size (px)

Citation preview

Page 1: OOP: Princípios e Padroes

Orientação a ObjetosPrincípios e Padrões

Page 2: OOP: Princípios e Padroes

Quem sou eu?‣ Programador no Glio

‣ Trabalhei na Dafiti, Emprego Ligado e Tripda

‣ Não mexo com PHP faz exatamente 1 ano

‣ Ruby

‣ @nelson_senna

Page 3: OOP: Princípios e Padroes

Agenda

‣ Uma breve introdução a OOP

‣ Os primos pobres do S.O.L.I.D

‣ Padrões de projeto (GoF)

Page 4: OOP: Princípios e Padroes
Page 5: OOP: Princípios e Padroes

O que é Orientação a Objetos?

Page 6: OOP: Princípios e Padroes
Page 7: OOP: Princípios e Padroes

O método é apoiado por quatro pilares

Page 8: OOP: Princípios e Padroes

Abstração

Page 9: OOP: Princípios e Padroes
Page 10: OOP: Princípios e Padroes

AbstraçãoOnde podemos errar?

Page 11: OOP: Princípios e Padroes

“If a precondition is violated, this means that a client has not satisfied its part of

the bargain, and hence the server cannot proceed reliably. Similarly, if a postcondition is violated, this means

that a server has not carried out its part of the contract, and so its clients can no longer trust the behavior of the server.”

Grady Booch

Page 12: OOP: Princípios e Padroes

Encapsulamento

Page 13: OOP: Princípios e Padroes
Page 14: OOP: Princípios e Padroes

EncapsulamentoOnde podemos errar?

Page 15: OOP: Princípios e Padroes

“No part of a complex system should depend on the internal details of any

other part”

Ingalls, D.

Page 16: OOP: Princípios e Padroes

Modularidade

Page 17: OOP: Princípios e Padroes
Page 18: OOP: Princípios e Padroes

ModularidadeOnde podemos errar?

Page 19: OOP: Princípios e Padroes

“The overall goal of the decomposition into modules is the reduction of

software cost by allowing modules to be designed and revised independently....

Each module's structure should be simple enough that it can be

understood fully;”

Britton and Parnas

Page 20: OOP: Princípios e Padroes

Hierarquia

Page 21: OOP: Princípios e Padroes
Page 22: OOP: Princípios e Padroes

HierarquiaOnde podemos errar?

Page 23: OOP: Princípios e Padroes

“Inheritance makes it possible to define new software in the same way we

introduce any concept to a newcomer, by comparing it with something that is

already familiar”

Cox, B.

Page 24: OOP: Princípios e Padroes

O que é um objeto?

Page 25: OOP: Princípios e Padroes
Page 26: OOP: Princípios e Padroes

Propriedades de um objeto

‣ Estado

‣ Comportamento

‣ Identidade

Page 27: OOP: Princípios e Padroes

“The state of an object encompasses all of the (usually static) properties of the

object plus the current (usually dynamic) values of each of these properties.”

Grady Booch

Page 28: OOP: Princípios e Padroes

“The state of an object represents the cumulative results of its behavior.”

Grady Booch

Page 29: OOP: Princípios e Padroes

“Assim como átomos podem existir repetidas vezes, a identidade possibilita

que múltiplas instâncias possam coexistir.”

Um troxa aí

Page 30: OOP: Princípios e Padroes

Objetos não são sacos de dados!

Page 31: OOP: Princípios e Padroes

Princípios

Page 32: OOP: Princípios e Padroes

Least Astonishment

Page 33: OOP: Princípios e Padroes

Command Query Separation

Page 34: OOP: Princípios e Padroes

Tell don’t ask

Page 35: OOP: Princípios e Padroes

Law of Demeter

Page 36: OOP: Princípios e Padroes

Padrões

Page 37: OOP: Princípios e Padroes

Decorator

Page 38: OOP: Princípios e Padroes

Strategy

Page 39: OOP: Princípios e Padroes

Chain of Responsibility

Page 40: OOP: Princípios e Padroes

Composite

Page 41: OOP: Princípios e Padroes

Template Method

Page 42: OOP: Princípios e Padroes

Facade

Page 43: OOP: Princípios e Padroes

Dúvidas?

Page 44: OOP: Princípios e Padroes

Avalie a palestra!

Page 45: OOP: Princípios e Padroes

Lista de imagens‣ Builders: https://flic.kr/p/mjweU

‣ Ikebana: https://flic.kr/p/6P7McX

‣ Boundary: https://flic.kr/p/3QrzLy

‣ Modularity: https://flic.kr/p/9sdBqQ

‣ Hierarchy: https://flic.kr/p/fgGtcP

‣ Objects: https://flic.kr/p/AD4FMh

Page 46: OOP: Princípios e Padroes

Referências‣ Tell don’t ask: https://pragprog.com/articles/tell-dont-ask

‣ OOP: Object-Oriented Analysis and Design with Applications - Grady Booch et al

‣ Law of Demeter: http://www.ccs.neu.edu/research/demeter/demeter-method/LawOfDemeter/paper-boy/demeter.pdf

‣ CQS: http://martinfowler.com/bliki/CommandQuerySeparation.html

‣ Least Astonishment: http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment

‣ Design Patterns: Design Patterns: Elements of Reusable Object-Oriented Software - Gamma et al

‣ Decorator: https://8thlight.com/blog/doug-bradbury/2016/07/18/not-a-decorator-ruby.html

‣ Template Method: https://medium.com/ruby-on-rails/what-i-learned-from-sandi-metz-9d0c94347b7f#.2y8u1prb4