Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t...
Transcript of Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t...
![Page 1: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/1.jpg)
Pic
ture
by
Ste
ve
Wa
ll [
htt
p:/
/ww
w.f
lic
kr.
co
m/p
ho
tos
/ste
ve
wa
ll/5
24
80
311
8/]Componentização e Reúso de Software
Fundamentos de Componentes e DesignVisão Interna
André SantanchèLaboratory of Information Systems – LIS
Instituto de Computação – UNICAMPJulho de 2018
![Page 2: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/2.jpg)
O que é um componente?Características Comuns
▪ Publica sua funcionalidade através de uma interface
▫ interface guia relacionamento componente x ambiente
▪ Entidade concebida para ser composta
▫ do latim componens, derivado de componere, que quer dizer “colocar junto”.
▪ Componentes podem ser aninhados em outros componentes
▫ componentes e sub-componentes
![Page 3: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/3.jpg)
O que é um componente?Características Desejáveis
▪ Contém código binário que implementa a funcionalidade declarada na interface
▪ Serviços acessíveis exclusivamente pela interface (black-box)
▪ Pacote padrão para distribuição
![Page 4: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/4.jpg)
O que é um componente?Características de Design
▪ Intercambiável dentro do ambiente
▪ Alta Coesão e Baixo Acoplamento
![Page 5: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/5.jpg)
Visão Interna
▪ Visão Externa (aula anterior)
▫ Foco: blackbox
▫ Abstração das funcionalidades de um componente vendo-o externamente através de suas interfaces
▫ Uso de componentes Composição→
▪ Visão Interna (esta aula)
▫ Foco: whitebox
▫ Como um componente é implementado internamente
![Page 6: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/6.jpg)
Notação Blackboxcomponente em notação blackbox
componente realiza interface (representação explícita)
componente realiza interface (representação lollipop)
![Page 7: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/7.jpg)
Realizando o Componente
pt.c08componentes.s10statistics.s03component
porta que associa interface a dependência de classe
classe que realiza o componente
compartimento opcional que mostraelementos que são parte do componente
dependência da porta/interfacecom a classe que a realiza
![Page 8: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/8.jpg)
Duas perspectivas de WhiteboxOMG UML (Cook et al., 2015)
![Page 9: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/9.jpg)
Whitebox com portasOMG UML (Cook et al., 2015)
![Page 10: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/10.jpg)
Componente EstatísticoImplementação – Whitebox
passo 1 – classe que implementa o componente
![Page 11: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/11.jpg)
Componente EstatísticoObjetivo
▪ Registrar um conjunto de números e calcular a soma e média destes números.
![Page 12: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/12.jpg)
Passo 1: Classe Estatística
pt.c08componentes.s10statistics.s01class
Statistics
- valueSet: Real [*] - last: Integer [1]
+ insertValue( in value: Real) + sum(): Real + average(): Real
![Page 13: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/13.jpg)
Exercício 01
▪ Faça um programa para calcular e exibir a soma e a média dos números: 50, 70 e 30.
![Page 14: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/14.jpg)
Componente EstatísticoImplementação – Whitebox
passo 2 – acesso via interface
![Page 15: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/15.jpg)
Dependency Inversion Principle (DIP)
▪ “Depender das Abstrações. Não depender das Concretizações.” (Martin, 2000)
![Page 16: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/16.jpg)
Passo 2: Interface Estatística
pt.c08componentes.s10statistics.s02interface
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real
Statistics
- valueSet: Real [*] - last: Integer [1]
![Page 17: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/17.jpg)
Exercício 02
▪ Adapte o programa anterior de modo que a variável seja do tipo da interface.
![Page 18: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/18.jpg)
Componente EstatísticoImplementação – Whitebox
passo 3 – transformando em um componente
![Page 19: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/19.jpg)
Notação Blackbox
▪ Esconde os detalhes internos da representação
pt.c08componentes.s10statistics.s03component
«component»StatisticsComponent
IStatistics
«component»StatisticsComponent
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real
![Page 20: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/20.jpg)
Notação Blackboxcomponente em notação blackbox
componente realiza interface (representação explícita)
componente realiza interface (representação lollipop)
«component»StatisticsComponent
IStatistics
«component»StatisticsComponent
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real
![Page 21: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/21.jpg)
«component»StatisticsComponentpackaged elements
StatisticsIStatistics
Realizando o Componente
pt.c08componentes.s10statistics.s03component
porta que associa interface a dependência de classe
classe que realiza o componente
compartimento opcional que mostraelementos que são parte do componente
dependência da porta/interfacecom a classe que a realiza
![Page 22: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/22.jpg)
Componente JavaBean
▪ Componentes são unidades de software auto-contidas e reusáveis que podem ser compostas visualmente em componentes compostos, applets, aplicações, e servlets usando ferramentas visuais de construção de aplicações.” (Sun, 2006)
Tradução do Inglês: “Components are self-contained, reusable software units that can be visually assembled into composite components, applets, applications, and servlets using visual application builder tools.” (Sun, 2006)
![Page 23: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/23.jpg)
JavaBeans
▪ Beans – componentes em Java
Características:
▫ Construtor sem argumentos
▫ Propriedades
▫ Introspecção
▫ Customização
▫ Persistência
▫ Eventos
![Page 24: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/24.jpg)
Perspectiva Orientada a Objetos de Componentes
▪ Componentes são associados a classes
▫ São instanciados como objetos◦ Não é um consenso
▪ Propriedades externamente observáveis
▫ Customizam a instância do componente◦ Não é um consenso
![Page 25: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/25.jpg)
Construtor sem Argumentos
▪ Permite a criação automática do componente
▪ Construtor com ação padrãopublic final static int STANDARD_SIZE = 50;private double valueSet[];private int last;public Statistics() { this(STANDARD_SIZE);}public Statistics(int size) { super(); valueSet = new double[size]; last = -1;} pt.c08componentes.s10statistics.s03component.v01
![Page 26: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/26.jpg)
Construtor sem Argumentos
▪ Construtor sem ação padrão public class Bean01Nome { public Bean01Nome() { /* nada */ }
▪ Construtor com ação padrão public class Bean02Circulo { private int raio; public Bean02Circulo() { raio = 50; }
pt.c08componentes.s01javabeans
![Page 27: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/27.jpg)
Exercício 03
▪ Adapte a classe implementada anteriormente para que ela se comporte como um componente, no pacote:
pt.c08componentes.s10statistics.s03component.v01
![Page 28: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/28.jpg)
Componente EstatísticoPropriedades
![Page 29: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/29.jpg)
PropriedadesNotação CORBA Component Model
«component»Component X
«Interface»
PropertyInterface
+ getPropertyA() : typeAProperty A
Property B
+ getPropertyB() : typeB
+ setPropertyA( in value : typeA)
PropertyB é somente leitura
![Page 30: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/30.jpg)
Propriedades de StatisticsBlackbox
«component»StatisticsComponent
+ valueSet: Real [*] + size: Integer [1] + last: Integer [1]
IStatistics
![Page 31: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/31.jpg)
Propriedades de StatisticsWhitebox
«component»StatisticsComponentpackaged elements
Statistics
+ valueSet: Real [*] + size: Integer [1] + last: Integer [1]
IStatistics
![Page 32: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/32.jpg)
Propriedades em Javabeans
![Page 33: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/33.jpg)
Propriedades
▪ Expostas através de métodos:
▫ prefixo “get” leitura
▫ prefixo “set” modificação private int raio; public int getRaio() { return raio; } public void setRaio(int raio) { this.raio = raio; }
pt.c08componentes.s01javabeans
![Page 34: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/34.jpg)
Propriedades
▪ Para diferenciar o atributo do parâmetro é usado o this:
public void setRaio(int raio) { this.raio = raio; }
pt.c08componentes.s01javabeans
![Page 35: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/35.jpg)
Propriedades
▪ Somente leitura
▫ não têm método “set”
▪ Propriedades não estão obrigadas a expor um atributo
public float getArea() { return 3.1416f + raio * raio; }
pt.c08componentes.s01javabeans
![Page 36: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/36.jpg)
Propriedades de Statistics
Interface
«component»StatisticsComponentpackaged elements
Statistics
+ valueSet: Real [*] + size: Integer [1] + last: Integer [1]
IStatistics
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real + getSize(): Integer + setSize( in size: Integer) + getLast(): Integer + getValueSet(): Integer + setValueSet( in valueSet: Integer) + getValueSet( in index: Integer): Real + setValueSet( in index: Integer, in value: Real)
Statistics
- valueSet: Real [*] - size: Integer [1] - last: Integer [1]
![Page 37: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/37.jpg)
Propriedades IndexadasvalueSet
▪ Acrescentam-se métodos:
▫ prefixo “get” com index retorna um item
▫ prefixo “set” com index altera um itemprivate double[] valueSet; public double[] getValueSet() {…} public void setValueSet(double[] valueSet){…}
public double getValueSet(int index) {…} public void setValueSet(int index,double valueSet){…}
pt.c08componentes.s10statistics.s03component.v02
![Page 38: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/38.jpg)
Exercício 04
▪ Adapte a componente implementado anteriormente para que ele suporte as três propriedades mencionadas:
pt.c08componentes.s10statistics.s03component.v02
![Page 39: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/39.jpg)
Componente EstatísticoInterface Requerida
Exemplo: Mostrando Resultados
![Page 40: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/40.jpg)
Interfaces RequeridasNotação CORBA Component Model
dependência entre a interface provida e a requerida
interface requeridainterface provida
![Page 41: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/41.jpg)
Interfaces RequeridasNotação CORBA Component Model
«component»Component B
«component»Component A
«Interface»
InterfaceX
+ operator( in parameter: type )
InterfaceXInterfaceX
«Interface»
InterfaceXReceptacle
+ connect( in component : InterfaceX )
interface requerida
interface provida
![Page 42: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/42.jpg)
Interface Provida e RequeridaComponente Client (blackbox)
dependência entre a interface provida e a requerida
interface requeridainterface provida
«component»StatisticsClientComponent
«component»StatisticsComponent
IStatistics IStatistics IStatisticsRun
![Page 43: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/43.jpg)
Interface Provida e RequeridaComponente Client (whitebox)
dependência entre a interface provida e a requerida
interface requeridainterface provida
«component»StatisticsComponent
Statistics
IStatistics
«component»StatisticsClientComponent
StatisticsClient
IStatistics IStatisticsRun
![Page 44: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/44.jpg)
Interface Provida e RequeridaComponente Client (blackbox)
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real
«Interface»IStatisticsReceptacle
+ connect( in statistics: IStatistics)
«Interface»IStatisticsRun
+ start()
«component»StatisticsClientComponent
«component»StatisticsComponent
IStatistics IStatistics IStatisticsRun
![Page 45: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/45.jpg)
IStatisticsReceptacle
«Interface»IStatistics
+ insertValue( in value: Real) + sum(): Real + average(): Real
Statistics
- valueSet: Real [*] - size: Integer [1] - last: Integer [1]
«Interface»IStatisticsRun
+ start()
StatisticsClient
«Interface»IStatisticsReceptacle
+ connect( in statistics: IStatistics)
«Interface»IStatisticsClient
![Page 46: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/46.jpg)
Exercício 05
▪ Construa um componente que se ligue ao StatisticsComponent, entregue a ele os 5 primeiros números de uma sequência de Fibonacci, e apresente a o somatório e a média calculados por ele.
![Page 47: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/47.jpg)
Exercício 06
▪ Crie um componente StatisticsSeries que se incorpore ao catálogo de componentes apresentado na aula anterior.
![Page 48: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/48.jpg)
“name”
«component»DataSetComponent
+ dataSource: String [1]
IInstancesProducer
«component»ChartComponent
+ title: String [1]
IColumnProducer
IRun
«component»ProjectionComponent
+ title: String [1] + attribute: String [1]
IInstancesProducer
IColumnProducer
«component»ProjectionComponent
+ title: String [1] + attribute: String [1]
IInstancesProducer
IColumnProducer
“age”
“days_recovery”
X_AXIS
Y_AXIS
![Page 49: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/49.jpg)
Exercício 06
▪ Crie um componente StatisticsSeries que se incorpore ao catálogo de componentes apresentado na aula anterior.
▪ Este componente deve se ligar aos outros apresentados, de modo que seja possível ver a média de idade e de tempo de recuperação por diagnóstico.
![Page 50: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/50.jpg)
Bibliografia▪ Bachmann, F.; Bass, L.; Buhman, C.; Dorda, S.C.; Long, F.; Robert,
J. & Wallnau, R.S.K. Volume II: Technical Concepts of Component-Based Software Engineering, 2nd Edition. Carnegie Mellon University, 2000.
▪ Broy, M.; Deimel, A.; Henn, J.; Koskimies, K.; Plásil, F.; Pomberger, G.; Pree, W.; Stal, M. & Szyperski, C. What characterizes a (software) component? Software -- Concepts & Tools, Springer-Verlag Heidelberg, 1998, 19, 49-56
▪ Hopkins, J. Component primer. Communications ACM, ACM Press, 2000, 43, 27-30.
▪ Mcilroy, M. D. Naur, P. & Randell, B. (ed.) Mass Produced Software Components. Software Engineering: Report of a conference sponsored by the NATO Science Committee, 1968.
![Page 51: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/51.jpg)
Bibliografia▪ Olsen, G. From COM to Common. Queue, ACM Press, 2006, 4, 20-26.
▪ Szyperski, C. Component Software: Beyond Object-Oriented Programming. Addison-Wesley Longman Publishing Co., Inc., 2002.
![Page 52: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/52.jpg)
André Santanchèhttp://www.ic.unicamp.br/~santanche
![Page 53: Fundamentos de Componentes e Design 2 asantanch/teaching/oop/2019-1/... · 2019. 5. 21. · P i c t u r e b y S t e v e W a l l [h t t p: / / w w w. f l i c k r. c o m / p h o t o](https://reader035.fdocumentos.tips/reader035/viewer/2022071503/6123ab0f0510de4bab3c6793/html5/thumbnails/53.jpg)
Licença▪ Estes slides são concedidos sob uma Licença Creative
Commons. Sob as seguintes condições: Atribuição, Uso Não-Comercial e Compartilhamento pela mesma Licença.
▪ Mais detalhes sobre a referida licença Creative Commons veja no link:http://creativecommons.org/licenses/by-nc-sa/3.0/
▪ Agradecimento a Steve Wall [http://www.flickr.com/photos/stevewall/] por sua fotografia “Dew drops” usada na capa e nos fundos, disponível em [http://www.flickr.com/photos/stevewall/524803118/]vide licença específica da fotografia.