The multiple inheritance allows you to define a new class that inherits the characteristics of several base classes which are not related to each other. The vehicle class encapsulates the data and behavior that describe vehicles along with other information, such as date of purchase, life, and maintenance schedules. Classes that support specific kinds of vehicles, such as trucks, airplanes, and cars are also derived from the vehicle class. The asset class encapsulates the data and behavior of the organization's assets, including acquiring date, and depreciation schedule data for accounting purposes. A company car, being both a vehicle and an asset, is represented by a class that derives from both base classes.
Now, the question arises that why the vehicles, asset data, and behavior are not included in the CompanyCar class? The reason is two-fold. First, not all vehicles are assets. The company might also hire cars on lease. Now, these hired vehicles cannot be considered as assets in the accounting sense. Second, not all assets are vehicles. The company may have many other assets, such as office furniture, copiers, and computers.
No comments:
Post a Comment