You are on page 1of 14

Aprendehaciendo

PR O G R A M A C I NO RIEN T A D AAO BJET O S

ClasesyObjetos

http://w w w .facebook.com /gcoronelc http://gcoronelc.blogspot.com gcoronelc@ gm ail.com


Derechosreservados www .isil.edu.pe

Ing.EricGustavoCoronel Castillo

NDICE

Objetivo Abstraccin Definicindeclasey objeto Implem entacindeclases Creaciny usodeobjetos ProyectoEjem plo Bibliografa

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 2

OBJET IVO

Entenderlos conceptosdeClasey Objeto,y suaplicacinenlasolucinde problem as sencillos.

Proble m a

Abstraccin

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 3

ABST R A C C I N Consisteencapturar, percibir y clasificar lascaractersticas(datos-atributos) y com portam ientos(operaciones) necesarias (relevantes) del m undoreal (procesoa sistem atizar) paradar solucinal problem a.
Persona + Nombre : String + Edad : Integer + Profesion : String + Caminar() + Correr() + Cantar() : String

NotacinU M L

Abstraccin

Animal + Raza : String + Genero : String + Comer()

Transporte + Tipo : String + Marca : String + Ao : Integer + Encender() : Boolean + Acelerar(Velocidad : Integer)

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 4

DEFINICI NDECLASEYOBJET O

CLASE
Unaclasedefineuntipodeobjetoenparticular. Porejem plo, laclaseEm pleadodefineatodoslostrabajadoresdeunaem presa.

Nom bredelaClase
Ejem plosdeNo m bresdeClase - Cliente - Factura - NotaC redito - Guia - Pedido - Matricula - CuentaM aestra

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 5

DEFINICI NDECLASEYOBJET O

OBJETO
Unobjetoesunainstanciadeunaclase. Porejem plo, cadatrabajadordeunaem presaesunainstanciadelaclase Em pleado .

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 6

DEFINICI NDECLASEYOBJET O

NotacinUM LdeO BJE T O


objPersona1: Persona + Nom bre: Jennifer + Edad: 34 + Profesion: C antante + Cam inar() + Correr() + Cantar():S tring
objPersona2: Persona

NotacinUM LdeClase
Persona + Nombre : String + Edad : Integer + Profesion : String + Caminar() + Correr() + Cantar() : String

+ Nom bre: Zidane + Edad: 40 + Profesion: Futbolista + Cam inar() + Correr() + Cantar():S tring

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 7

IM PLE M E N TA C I NDECLAS ES

SINTAXIS
publicclassNom breC lase{ // Definicindecam pos // Definicindem todos
}
El nom bredel archivodebetenerel m ism onom bredelaclase.
Por ejem plo,si laclasesellam aProductoel nom bredel archivo quecontienea laclasesedebellam arProducto.java.

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 8

IM PLE M E N TA C I NDECLAS ES

ATRIBUTO S
Representaunapropiedaddeunaentidad. Cadaatributodeunobjetotieneunvalorqueperteneceaundom iniodevalores determ inado. EnJavaseimplem entancreandovariablesanivel declase.

publicclassV enta{ // Variablesqueim plem entacindeatributos privateInteger id; privateDatefecha; privateStringcliente; privateDoubleim porte;

}
I SI L Derechosreservados Ing. GustavoCorone l www .isil.edu.pe 9

IM PLE M E N TA C I NDECLAS ES

OPERACIO NES
Sonserviciosproporcionadoporlaclasequepuedenser solicitadosporotras clases. Determ inanel com portam ientodel objeto. Laim plem entacinenJavaserealizam ediantem todos,
publicclassV enta{ // Implem entacindeatributos privateInteger id; ... // Implem entacindeoperaciones publicbooleanbuscar() { ... ... } ... }
I SI L Derechosreservados Ing. GustavoCorone l www .isil.edu.pe 10

IM PLE M E N TA C I NDECLAS ES

DEFINICI NDEMTO D O S
public<tipo>nom breM todo( [ parm etros ] ) { //Implem entacin [ returnvalorRetorno; ] } <tipo> return Determ inael tipodedatoqueretornael m todo, si noretornaningn valorseutilizavoid. Estasentenciafinalizalaejecucindel m todo, seacom paadeunvalor cuandoel mtododeberetornar unresultado.

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 11

CREA C I NYUSODEOBJET O S

OPERADO RNEW
Nom breC lasevariable=newNom breC lase(); Nom breC lasevariable=null; variable=newNom breC lase();

ACCESOALOSMTO DO S
variable.nom breM todo( )

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 12

PRO YE C TOEJE M PL O

Laem presa"TodoBarato" necesitafacilitarla elaboracindelos pedidos querealizansusem pleadosa sus proveedores,el problem aradicaal mom entodecalcularel impuesto. La em presahasolicitadoa sudepartam entodesistem aselaborarun program aenJavaqueperm itaingresarel im portedel pedido,y calculeel impuestoy el total quesedebepagaral proveedor.

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 13

BIBLIO G R A F A

I SI L Derechosreservados

Ing. GustavoCorone l www .isil.edu.pe 14

You might also like