Shapes Class

Circle, Square and Triangle all share some characteristics: they are all kinds of shape. We can model that by defining a higher superclass.

Shapes Class

Circle, Square and Triangle all share some characteristics: they are all kinds of shape. We can model that by defining a higher superclass.

Shapes Class

Circle, Square and Triangle all share some characteristics: they are all kinds of shape. We can model that by defining a higher superclass.

Shapes Class

All shapes have the same basic state information, and may need direct access to their position data. This means that x, y and size are no longer private to Shape, but neither are they public to everyone. Instead, they are protected , accessible only to Shape and its subclasses.

Shapes Class

All shapes have the same basic state information, and may need direct access to their position data. This means that x, y and size are no longer private to Shape, but neither are they public to everyone. Instead, they are protected , accessible only to Shape and its subclasses.

Shapes Class

All shapes have the same basic state information, and may need direct access to their position data. This means that x, y and size are no longer private to Shape, but neither are they public to everyone. Instead, they are protected , accessible only to Shape and its subclasses.

Shapes Class

All shapes have the same basic state information, and share the same moveTo behaviour. The drawing method differs for each one, so we will just leave it blank and assume that everyone would override it.

Shapes Class

All shapes have the same basic state information, and share the same moveTo behaviour. The drawing method differs for each one, so we will just leave it blank and assume that everyone would override it.

Shapes Class

All shapes have the same basic state information, and share the same moveTo behaviour. The drawing method differs for each one, so we will just leave it blank and assume that everyone would override it.

Shapes Class

Now each specific shape class (Cirle, Square and Triangle) can extend the general Shape class, inheriting the necessary state and behaviour.

Shapes Class

Now the driver applet can delare its variable to be of type Shape, allocating whichever specific type of shape it wishes. Indeed it could even have an array of Shapes containing some Triangles, some Circles and some Squares.

Shapes Class

Of course, there should never be an actual Shape object, because it wouldn't know how to draw itself. Contrariwise, every properly defined specific shape class must define a draw() method. We can declare the Shape draw method to be abstract

Shapes Class

Of course, there should never be an actual Shape object, because it wouldn't know how to draw itself. Contrariwise, every properly defined specific shape class must define a draw() method. We can declare the Shape draw method to be abstract

Shapes Class

Of course, there should never be an actual Shape object, because it wouldn't know how to draw itself. Contrariwise, every properly defined specific shape class must define a draw() method. We can declare the Shape draw method to be abstract

Shapes Class

Of course, there should never be an actual Shape object, because it wouldn't know how to draw itself. Contrariwise, every properly defined specific shape class must define a draw() method. We can declare the Shape draw method to be abstract

Shapes Class

Of course, there should never be an actual Shape object, because it wouldn't know how to draw itself. Contrariwise, every properly defined specific shape class must define a draw() method. We can declare the Shape draw method to be abstract

Shapes Class

This turns the whole Shape class into an abstract class

Shapes Class

This turns the whole Shape class into an abstract class

Shapes Class

This turns the whole Shape class into an abstract class

Shapes Class

An abstract class contains a mixture of defined behaviour and loosely specified behaviour. Alternatively, an interface is a specification of a subset of a class' behaviour. It is entirely abstract.

class Circle {
private int x=50, y=50;
private int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Circle {
private int x=50, y=50;
private int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
private int x=50, y=50;
private int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
private int x=50, y=50;
private int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
private int x=50, y=50;
private int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
	g.drawOval(x, y, size, size);
	}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g){
		}

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g);

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g);

}

class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g);

}

abstract class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g);

}

abstract class Shape {
protected int x=50, y=50;
protected int size=20;

public void moveTo(int xpos, int ypos){
	x=xpos; y=ypos;
	}

public abstract void draw(java.awt.Graphics g);

}