Orientação a Objetos
Princípios e Padrões
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
Agenda
‣ Uma breve introdução a OOP
‣ Os primos pobres do S.O.L.I.D
‣ Padrões de projeto (GoF)
O que é Orientação a
Objetos?
O método é apoiado por
quatro pilares
Abstração
Abstração
Onde podemos errar?
“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
Encapsulamento
Encapsulamento
Onde podemos errar?
“No part of a complex system should
depend on the internal details of any
other part”
Ingalls, D.
Modularidade
Modularidade
Onde podemos errar?
“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
Hierarquia
Hierarquia
Onde podemos errar?
“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.
O que é um objeto?
Propriedades de um
objeto
‣ Estado
‣ Comportamento
‣ Identidade
“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
“The state of an object represents the
cumulative results of its behavior.”
Grady Booch
“Assim como átomos podem existir
repetidas vezes, a identidade possibilita
que múltiplas instâncias possam
coexistir.”
Um troxa aí
Objetos não são sacos
de dados!
Princípios
Least Astonishment
Command Query
Separation
Tell don’t ask
Law of Demeter
Padrões
Decorator
Strategy
Chain of Responsibility
Composite
Template Method
Facade
Dúvidas?
Avalie a palestra!
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
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

OOP: Princípios e Padroes