9 ms·
> the same shape class inheritance example you'll see in every introductory Java textbook Here's what's shown: DisplayObject DisplayMedium
by igouy 1y ago
> the same shape class inheritance example you'll see in every introductory Java textbook
Here's what's shown:
DisplayObject
DisplayMedium
Form
Cursor
DisplayScreen
InfiniteForm
OpaqueForm
Path
Arc
Circle
Curve
Line
LinearFit
Spline
Do you have an example of that being shown in an introductory Java textbook?
- ndiddy 1y agoSure, why not. Obviously if you mean "do you have an example of that exact class hierarchy being shown in an introductory Java textbook" no I don't, you win. However, the example of a program that uses a class inheritance hierarchy defined at compile time to represent all the different types of shapes it can operate with is used all over the place, and that's what I was referring to. Some examples: Introduction to Programming in Java by J. N. Patterson Hume and Christine Stephenson, page 392 Object-oriented Programming with Java by Barry J. Holmes and Daniel T. Joyce, page 544 Understanding object-oriented programming with Java by Timothy Budd, page 304 Teach yourself Java by Joseph O'Neil, page 184 Java in a Nutshell by Benjamin J. Evans, page 128 Java for Students by Douglas Bell and Mike Parr, page 490 Data structures and problem solving using Java by Mark Allen Weis, page 84 See here for a good article that goes over the downsides of this approach, and how it hurts both readability and performance: https://www.computerenhance.com/p/clean-code-horrible-performance https://www.computerenhance.com/p/clean-code-horrible-perfor...
- igouy 1y ago> no I don't, you win Because what they are actually like is java.awt — they are the classes used to implement graphics in Smalltalk-80, not some made-up example. (The "Java in a Nutshell 8th ed, I found has no page numbers. There's a "Subclasses and Inheritance" section which shows how to code PlaneCircle as a subclass of Circle class. afaict That's a couple of made-up classes that exist solely to show things that can be done with Java classes. Not an example of "compile-time hierarchy of encapsulation that matches the domain model". Later the authors use class A and class B for their examples.)