1 / 10

INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES

INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES. INGENIERIA EN SISTEMAS COMPUTACIONALES. LUCERO ARENAS FLORES. CLASE BASE.

Télécharger la présentation

INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INSTITUTO TECNOLOGICO SUPERIOR DE LIBRES INGENIERIA EN SISTEMAS COMPUTACIONALES LUCERO ARENAS FLORES

  2. CLASE BASE

  3. 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.

  4. 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 }

  5. 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

  6. 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) {

  7. 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);

  8. 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 caja class Box extends GraphObj { int height, width; Box(int lx, int ly, int hx, int hy) {

  9. super( ... ); // Ejercicio ... } void Paint(Graphics g) { ... // Ejercicio } }

  10. GRACIAS

More Related