1+ import { Endereco } from "../endereco/endereco" ;
2+
3+ abstract class Pessoa {
4+
5+ //////////////////////////
6+ //Atributos de Instância//
7+ //////////////////////////
8+
9+ protected _matricula : number = 0 ;
10+ private _nome : string = '' ;
11+ private _sobrenome : string = '' ;
12+ private _sexo : string = '' ;
13+ private _CPF : string = '' ;
14+ private _idade : number = 0 ;
15+ private _brasileiro : boolean = true ;
16+ private _enderecos : Endereco [ ] = [ ] ; // Ou let enderecos: Array<string>; - Associação Estrutural - Agregação - A partir de atributo
17+
18+ ///////////////////////
19+ //Atributos Estáticos//
20+ ///////////////////////
21+
22+ private static quantidadePessoas : number = 0 ;
23+
24+ ///////////////
25+ //Gets e Sets//
26+ ///////////////
27+
28+ public get matricula ( ) : number {
29+ return this . _matricula ;
30+ }
31+
32+ protected set matricula ( valor : number ) {
33+ this . _matricula = valor ;
34+ }
35+
36+ public get nome ( ) : string {
37+ return this . _nome ;
38+ }
39+
40+ public set nome ( valor : string ) {
41+ this . _nome = valor ;
42+ }
43+
44+ public get sobrenome ( ) : string {
45+ return this . _sobrenome ;
46+ }
47+
48+ public set sobrenome ( value : string ) {
49+ this . _sobrenome = value ;
50+ }
51+
52+ public get sexo ( ) : string {
53+ return this . _sexo ;
54+ }
55+
56+ public set sexo ( value : string ) {
57+ this . _sexo = value ;
58+ }
59+
60+ public get CPF ( ) : string {
61+ return this . _CPF ;
62+ }
63+
64+ public set CPF ( valor : string ) {
65+ let padraoCPF : RegExp = / ^ [ 0 - 9 ] { 3 } \. [ 0 - 9 ] { 3 } \. [ 0 - 9 ] { 3 } \- [ 0 - 9 ] { 2 } $ / ; // Associação Comportamental - Dependência
66+ if ( padraoCPF . test ( valor ) ) {
67+ this . _CPF = valor ;
68+ }
69+ else {
70+ throw Error ( "CPF Inválido" ) ;
71+ }
72+ }
73+
74+ public get idade ( ) : number {
75+ return this . _idade ;
76+ }
77+
78+ public set idade ( value : number ) {
79+ this . _idade = value ;
80+ }
81+
82+ public get brasileiro ( ) : boolean {
83+ return this . _brasileiro ;
84+ }
85+
86+ public set brasileiro ( value : boolean ) {
87+ this . _brasileiro = value ;
88+ }
89+
90+ public get enderecos ( ) : Endereco [ ] {
91+ return this . _enderecos ;
92+ }
93+
94+ public set enderecos ( value : Endereco [ ] ) {
95+ this . _enderecos = value ;
96+ }
97+
98+ //////////////
99+ //Construtor//
100+ //////////////
101+
102+ constructor ( nome : string , sobrenome : string , sexo : string , CPF : string , idade : number , brasileiro : boolean , enderecos : Endereco [ ] ) {
103+ this . nome = nome ;
104+ this . sobrenome = sobrenome ;
105+ this . sexo = sexo ;
106+ this . CPF = CPF ;
107+ this . idade = idade ;
108+ this . brasileiro = brasileiro ;
109+ this . enderecos = enderecos ;
110+ Pessoa . quantidadePessoas ++ ;
111+ }
112+
113+ ////////////////////////
114+ //Métodos de Instância//
115+ ////////////////////////
116+
117+ public exibirNomeCompleto ( ) : string {
118+ return ( `O nome completo é: ${ this . nome } ${ this . sobrenome } ` ) ;
119+ }
120+
121+ public recuperarEndereco ( posicao : number ) : Endereco {
122+ return this . enderecos [ posicao ] ;
123+ }
124+
125+ /////////////////////
126+ //Métodos Estáticos//
127+ /////////////////////
128+
129+ public static getQuantidadePessoas ( ) : number {
130+ return Pessoa . quantidadePessoas ;
131+ }
132+
133+ /////////////////////
134+ //Métodos Abstratos//
135+ /////////////////////
136+
137+ //Método abstrato - Sem implementação
138+ //Usado para garantir que as classes que herdem de pessoa possuam uma implementação do gerarMatricula,
139+ //assim é possivel que cada classe que herde de pessoa implemente sua forma específica de gerar matricula (Polimorfismo)
140+ protected abstract gerarMatricula ( ) : number ;
141+
142+ }
143+
144+ export { Pessoa }
0 commit comments