UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

23
Goyaz Persistência sem esforços UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador

Transcript of UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Page 1: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Goyaz Persistência sem

esforçosUNIVERSIDADE CATÓLICA DE BRASÍLIA2011

PAULO LIMAaluno

FERNANDO GOULARTorientador

Page 2: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

IntroduçãoApresentação dos conceitos básicos

Page 3: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Orientação a Objetos VS

Bancos de Dados Relacionais

Page 4: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Orientação a Objetos

Virtudes: Abstração; Herança; Reusabilidade; Regras de negócio; Encapsulamento; Camadas

Vícios: Otimização; Complexidade; Desorganização;

Page 5: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Bancos de dados

Virtudes Otimização; Boa visualização

dos dados; Segurança; Independência de

paradigmas; Padrão industrial;

Vícios: Conectores; Diversos dialetos; Complexidade nas

instruções; Manutenibilidade;

Page 6: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Por que juntá-las?

Manter os dados da aplicação coesos e seguros;

Permitir que diferentes aplicações utilizem os mesmos dados; Existem outras formas de se obter esse

resultado; Desenvolver as regras de negócio

com mais facilidade;

Page 7: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Como juntá-las?

Camada de persistência; Padrões de projeto;

Table data gateway; Row data gateway; Data mapper; Active record; Outras opções / variações;

Manutenibilidade;

Page 8: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Padrões de ProjetoUma visão sobre casos de sucesso na resolução dos

problemas apresentados

Page 9: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Table Data Gateway

Definição: Classe que irá conter

todos os códigos SQL para acesso a uma determinada tabela ou view;

Separação das regras de negócio;

Uma classe por tabela, evitando bagunça;

Deve retornar somente um tipo de dado;

Page 10: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Row Data Gateway

Consiste em representar um único registro em uma determinada tabela no banco de dados;

Overhead de memória;

Page 11: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Row Data Gateway

Page 12: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Data Mapper

Isolamento entre os objetos de negócios e os dados no banco;

Transparência; Mapeamento entre

objetos na aplicação e tabelas no banco;

Page 13: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Active Record

Um único objeto com métodos comportamentais e métodos para realizar a persistência;

Caso seja muito complexo o objeto a ser persistido, o desempenho caí drasticamente;

Page 14: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Herança em tabela única

Page 15: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Herança em tabelas concretas

Page 16: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Herança tabela classe

Page 17: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Qual padrão escolher?

Considere: Complexidade da aplicação; Parque computacional; Tempo disponível; Capacidade técnica;

Faça adaptações, caso necessário;

Page 18: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

GoyazProtótipação em PHP

Page 19: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Dificultadores

Como descobrir a quem pertence um determinado atributo? Caso hajam dois atributos na classe pai

e filha com o mesmo nome, não é possível determinar de qual se trata;

Reflexão;

Page 20: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Reflexão

Técnica que consistem em levantar informações sobre um determinado recurso em tempo de execução;

Nativamente implementado no PHP;

Page 21: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Na prática

Agenda: Models; Actions;

Page 22: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Dúvidas?

Page 23: UNIVERSIDADE CATÓLICA DE BRASÍLIA 2011 PAULO LIMA aluno FERNANDO GOULART orientador.

Agradecimentos