instituto tecnologico superior de libres
DESCRIPTION
INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES. INGENIERIA EN SISTEMAS COMPUTACIONALES. LUCERO ARENAS FLORES. CLASE BASE. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/1.jpg)
INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES
INGENIERIA EN SISTEMAS COMPUTACIONALES
LUCERO ARENAS FLORES
![Page 2: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/2.jpg)
CLASE BASE
![Page 3: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/3.jpg)
Una clase abstracta es una clase que se introduce sólo para que se deriven nuevas clases de ella, no para que se creen objetos con su nombre. Del mismo modo, un método abstracto es un método que se introduce para que sea redefinido en una clase derivada.
![Page 4: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/4.jpg)
abstract class GraphObj{ int x, y; // La posición central GraphObj(int ix, int iy) { x= ix; y= iy; } // constructor void Move(int dx, int dy) { x+= dx; y+= dy; } abstract void Paint(Graphics g); // Paint es abstracto}
![Page 5: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/5.jpg)
Esta clase no se puede usar para crear un objeto, por lo que lo siguiente es un error:GraphObj gf= new GraphObj(10,20); // error
![Page 6: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/6.jpg)
La idea es que sólo se pueden crear objetos de clases derivadas de la clase anterior:class Line extends GraphObj{ // x e y se heredan int ix, iy; GraphObj(int aix, int aiy, int afx, int afy) {
![Page 7: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/7.jpg)
super((aix+afx)/2, (aiy+afy)/2); ix= aix; iy= aiy; } void Paint(Graphics g) { g.DrawLine(xi,yi,x+(x-xi),y+(y-yi)); } // Move se hereda de GraphObj}
// Ahora sí!Line line= new Line(0,0, 10,20);
![Page 8: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/8.jpg)
El principio es que se use varias veces la clase abstracta para definir varias otras clases que poseen un conjunto común de métodos: Paint y Move.// Una cajaclass Box extends GraphObj{ int height, width; Box(int lx, int ly, int hx, int hy) {
![Page 9: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/9.jpg)
super( ... ); // Ejercicio ... } void Paint(Graphics g) { ... // Ejercicio }}
![Page 10: INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812e14550346895d937f1a/html5/thumbnails/10.jpg)
GRACIAS