Class inheritance is basically just a mechanism for extending an application's functionality by reusing
functionality in parent classes. It lets you define a new kind of object rapidly in terms of an old one. It lets
you get new implementations almost for free, inheriting most of what you need from existing classes.
However, implementation reuse is only half the story. Inheritance's ability to define families of objects with
identical interfaces (usually by inheriting from an abstract class) is also important. Why? Because
polymorphism depends on it.
When inheritance is used carefully (some will say properly), all classes derived from an abstract class will
share its interface. This implies that a subclass merely adds or overrides operations and does not hide
operations of the parent class. All subclasses can then respond to the requests in the interface of this abstract
class, making them all subtypes of the abstract class.
There are two benefits to manipulating objects solely in terms of the interface defined by abstract classes:
1. Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the
interface that clients expect.
2. Clients remain unaware of the classes that implement these objects. Clients only know about the
abstract class(es) defining the interface.
This so greatly reduces implementation dependencies between subsystems that it leads to the following
principle of reusable object-oriented design:
分享到:
相关推荐
Inheritance, “Programming to an Interface not an Implementation” Lambdas, Sequential and Parallel Streams, Functional Interfaces with Default and Static Methods, Immutability JavaFX GUI, 2D and 3D ...
Based on the provided information from "iOS 5 Programming Cookbook" by Vandad Nahavandipoor, we can derive a comprehensive set of knowledge points related to iOS development using Objective-C....
The ability of using MATLAB functions makes MATFOR an ideal tool for those who create prototypes using MATLAB, then do implementation in C++ and other programming languages. Through the use of MATFOR...
### Mac Programming for Absolute Beginners ... The book's structured approach, combined with practical examples, makes it an excellent resource for anyone looking to start programming on the Mac.
This application report describes the implementation of TI's Flash application program interface (API), the software interface to TI's Flash algorithms. Understanding the fundamentals of the Flash API...
Equally emphasizing theory and practice, the book provides an understanding not only of the principles of 3D computer graphics, but also the use of the OpenGL® Application Programming Interface (API...
Equally emphasizing theory and practice, the book provides an understanding not only of the principles of 3D computer graphics, but also the use of the OpenGL® Application Programming Interface (API...
Equally emphasizing theory and practice, the book provides an understanding not only of the principles of 3D computer graphics, but also the use of the OpenGL® Application Programming Interface (API...
**Answer**: A legacy API (Application Programming Interface) is an interface that was designed for an older version of a system or application and is no longer actively maintained or updated....
However, implementation code properly belongs in .cc files, and we do not like to have much actual code in .h files unless there is a readability or performance advantage. If an inline function ...
The POSIX 1003.1-2001 standard defines an application programming interface (API) for writing multithreaded applications. This interface is known more commonly as pthreads. A good number of modern ...
This specification was developed in response to a perceived need for a standardized programming inter-face to digitizing tablets, three dimensional position sensors, and other pointing devices by a ...
and proceeds through sequential logic and memory circuits used to interface to mod- ern PCs. Professor Kleitz uses his vast experience of teaching electronics online and in class from his best-selling...
Secondly, the user interface should allow users to upload the cover image (the image that will carry the hidden information) and the secret message. Then, the LSB algorithm is applied to embed the ...
(An interesting observation is that Action is a class and not an interface. Action started as an interface and changed into a class over time. Nothing's perfect.) The Error classes The UML diagram ...
An Easy Way to Remember the 8086 Memory Addressing Modes 4.6.2.8 - Some Final Comments About 8086 Addressing Modes 4.6.3 - 80386 Register Addressing Modes 4.6.4 - 80386 Memory Addressing ...
The implementation of an online answer system not only facilitates student information management and online examinations but also significantly promotes the informatization of the education sector, ...
wanted it to run on as many platforms as possible, so an NFS porting group was assigned the task of helping other companies implement NFS on their computers. Our NFS evangelism was a little ahead of ...
比如,使用接口(Interface)而不是具体的实现类,可以实现设计原则中的“面向接口编程”(Programming to an Interface, not an Implementation),这有助于减少耦合度和提高代码的可扩展性。此外,组合模式在.NET...