Lecture5-Jan27-Abstract

Lecture5-Jan27-Abstract - 1 1 41 COP 3503 SPRING 2012...

This preview shows pages 1–14. Sign up to view the full content.

1 / 41 COP 3503 SPRING 2012 Shayan Javed Lecture 5 Programming 1

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

View Full Document
2 / 41 Abstract Classes
3 / 41 Abstract classes From the previous lecture: public class GeometricObject { protected String Color; protected String name; protected float area; // Constructors…

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

View Full Document
4 / 41 Abstract classes So we can do: GeometricObject gObj = new GeometricObject (“AnObject, Red”);
5 / 41 Abstract classes So we can do: GeometricObject gObj = new GeometricObject (“AnObject, Red”); But does it make sense to do this? What is a “GeometricObject” by itself?

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

View Full Document
6 / 41 Abstract classes Solution: Make it abstract !
7 / 41 Abstract classes Solution: Make it abstract ! public abstract class GeometricObject {

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

View Full Document
8 / 41 Abstract classes Used for defining classes for “ abstract concepts. (‘GeometricObject’, ‘Animal’, etc.)
9 / 41 Abstract classes Used for defining classes for “ abstract concepts. (‘GeometricObject’, ‘Animal’, etc.) Then define “ concrete ” concepts as subclasses. (Circle, Rectangle, etc.)

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

View Full Document
10 / 41 Abstract classes Used for defining classes for “ abstract concepts. (‘GeometricObject’, ‘Animal’, etc.) Then define “ concrete ” concepts as subclasses. (Circle, Rectangle, etc.) More strictness = less room for ambiguity/error.
11 / 41 Abstract classes Every GeometricObject has an area.

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

View Full Document
12 / 41 Abstract classes Every GeometricObject has an area. But getArea() defined differently for concrete objects.
Abstract classes Every GeometricObject has an area. But

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 42

Lecture5-Jan27-Abstract - 1 1 41 COP 3503 SPRING 2012...

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

View Full Document
Ask a homework question - tutors are online