Classes In Java (8)

Classes In Java (8) - COP 3330: Object-Oriented Programming...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3330: Classes In Java – Part 3 Page 1 © Dr. Mark Llewellyn COP 3330: Object-Oriented Programming Summer 2011 Classes In Java – Part 3 Abstract Classes and Interfaces Department of Electrical Engineering and Computer Science Computer Science Division University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3330/sum2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Classes In Java – Part 3 Page 2 © Dr. Mark Llewellyn Abstract Classes In the inheritance hierarchy, classes become more specific and concrete with each new subclass. If you move from a subclass back up to a superclass, the classes become more general and less specific. Class design should ensure that a superclass contains common features of its subclasses. Sometimes a superclass is so abstract that it cannot have any specific instances. Such a class is called an abstract class .
Background image of page 2
COP 3330: Classes In Java – Part 3 Page 3 © Dr. Mark Llewellyn Abstract Classes Recall our GeometricObject class that was the superclass for Circle and Rectangle . The GeometricObject class models common features of geometric objects. Both the Circle and Rectangle classes contain the getArea() and getPerimeter() methods for computing the area and perimeter of a circle and a rectangle.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Classes In Java – Part 3 Page 4 © Dr. Mark Llewellyn Rectangle − width: double − height: double + Rectangle() + Rectangle(width: double, height: double) + getWidth(): double + setWidth(width: double): void + getHeigth(): double + setHeight(height: double): void + getArea(): double + getPerimeter(): double Circle − radius: double + Circle() + Circle(radius: double) + getRadius(): double + setRadius(radius: double): void + getArea(): double + getPerimeter(): double + getDiameter(): double + printCircle(): void GeometricObject − color: String − filled: boolean − dateCreated: java.util.Date + GeometricObject() + getColor(): String + setColor(color: String): void + isFilled(): boolean + setFilled(filled: boolean): void + getDateCreated(): java.util.Date + toString(): String Original UML classes
Background image of page 4
COP 3330: Classes In Java – Part 3 Page 5 © Dr. Mark Llewellyn The original Rectangle class
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Classes In Java – Part 3 Page 6 © Dr. Mark Llewellyn The original Circle class
Background image of page 6
COP 3330: Classes In Java – Part 3 Page 7 © Dr. Mark Llewellyn Abstract Classes However, our earlier design was somewhat lacking in that you can compute the area and perimeter of all geometric objects, hence these are not properties of circles or rectangles, but of geometric objects. A better design would be to declare the getArea() and getPerimeter() methods in the GeometricObject class. But there is a problem doing this. What is the problem?
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Classes In Java – Part 3 Page 8 © Dr. Mark Llewellyn Abstract Classes The problem is that in the GeometricObject class we can’t provide an implementation for these methods because their implementation
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 59

Classes In Java (8) - COP 3330: Object-Oriented Programming...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online