ch13 - Alice in Action with Java Chapter 13 Object-Oriented...

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

View Full Document Right Arrow Icon
Alice in Action with Java Chapter 13 Object-Oriented Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 2 Objectives Design and build class hierarchies Understand inheritance and polymorphism Override inherited methods Build abstract classes
Background image of page 2
Alice in Action with Java 3 Object-Oriented Programming OOP: using class hierarchies to model object relations Review concepts A subclass is a specialized version of a superclass Subclasses inherit the members of their superclasses A class hierarchy familiar to biologists Kingdom, phylum, class, order, family, genus, species OO programmers should think like biologists
Background image of page 3

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 4 Object-Oriented Programming (continued)
Background image of page 4
Alice in Action with Java 5 Introductory Example: Drawing Shapes Problem: create logo using square, circle, triangle
Background image of page 5

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 6 Introductory Example: Drawing Shapes (continued)
Background image of page 6
Alice in Action with Java 7 Design The user story for Logo.java Open a window Draw a red square, a green circle, and a blue triangle Modeling the objects in the program Use the Plotter class to create the window Build Square , Circle , and Triangle classes Members common to the three new classes public getColor() public draw() private Color myColor
Background image of page 7

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 8 Design (continued)
Background image of page 8
Alice in Action with Java 9 Design (continued) Common class members should be in a superclass Principle: define member once, use multiple times Application: design Shape to contain three members Extending the class hierarchy A triangle is a polygon and a square is a polygon Create Polygon class to capture common members Object-oriented design (OOD) Organize problem classes into an inheritance hierarchy Object-oriented programming Process of converting OO design into an OO program
Background image of page 9

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 10 Design (continued)
Background image of page 10
Alice in Action with Java 11 Implementing the Design The Shape class is implemented first (most general) Members of Shape A Shape() constructor A instance variable to store the Color An accessor for the Color variable A draw() method Shape handle refers to Circle , Triangle , Square Abstract method: declared (not defined) in superclass Abstract class: contains abstract (undefined) methods
Background image of page 11

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 12 Implementing the Design (continued)
Background image of page 12
Alice in Action with Java 13 Implementing the Design (continued)
Background image of page 13

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 14 Implementing the Design (continued) Circle extends (becomes a subclass of) Shape Features of the Circle class Instance variables: radius, (x, y) coordinates of center Constructor uses super() to call superclass constructor Constructor also initializes Circle ’s instance variables An accessor for the radius An accessor for a Point A definition for draw() Point class: structured type models (x,y) coordinates Subclass uses super to access superclass members
Background image of page 14
Alice in Action with Java 15 Implementing the Design (continued)
Background image of page 15

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

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 59

ch13 - Alice in Action with Java Chapter 13 Object-Oriented...

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

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