Practical Object-Oriented Design: An Agile Primer Using Ruby by Sandi Metz

Practical Object-Oriented Design: An Agile Primer Using Ruby by Sandi Metz

Author:Sandi Metz [Metz, Sandi]
Language: eng
Format: epub, pdf
Publisher: Pearson Education
Published: 2018-07-09T23:00:00+00:00


6.4.1 Creating an Abstract Superclass

Figure 6.6 shows a new class diagram where Bicycle is the superclass of both MountainBike and RoadBike. This is your goal; it’s the inheritance structure you intend to create. Bicycle will contain the common behavior, and MountainBike and RoadBike will add specializations. Bicycle’s public interface should include spares and size, and the interfaces of its subclasses will add their individual parts.

Bicycle now represents an abstract class. Chapter 3, “Managing Dependencies,” defined abstract as being disassociated from any specific instance, and that definition still holds true. This new version of Bicycle will not define a complete bike, just the bits that all bicycles share. You can expect to create instances of MountainBike and RoadBike, but Bicycle is not a class to which you would ever send the new message. It wouldn’t make sense; Bicycle no longer represents a whole bike.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.