pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

Object Oriented Programming 6

Now that we know what a class is, and how to derive classes using inheritance, we’ll take a quick look at the slightly thorny issue of multiple inheritance. In the simplest terms, this is when a derived class has more than one base class. Theoretically a class may derive from any number of base classes, but in practice two or perhaps three base classes may be used.

One of the problems with using multiple inheritance is that different languages implement it differently. For instance, in C++ any class can derive all methods and data from parent classes, while Java on the other hand is very restrictive in how multiple inheritance can be applied. Ironically, the restrictions Java imposes mean that many designers and programmers find multiple inheritance is in fact more usable.

A common problem with multiple inheritance is the Diamond of Death effect. In this case, a class A derives from two parent classes B and C, but these two parent classes both derive from the same base class D. Because the new class A derives the entire tree structure of both parents, it will have inherited two copies of the superclass D. Though C++ provides the virtual base class construct to get around this issue, it is still a lurking danger for object oriented designs.

The confusion that can arise with multiple inheritance means that it needs to be treated with a little more respect than might be assumed. The bottom line is, don’t take it for granted!

As a simple example of multiple inheritance, think of our game characters. We can design our hierarchy a little differently to make use of multiple inheritance.

A

Here the playerCharacter class inherits from both class gameCharacter and class point. In this design, the currentLoc variable member of the gameCharacter class is no longer necessary, as the posX and posY attributes are now member variables of any gameCharacter objects created. This might seem to have great advantages, and it’s true that multiple inheritance can be extremely useful. However, the warning is clear – use the technique carefully. Remember that encapsulation is to a great extent the point of object oriented design, enabling secure, understandable and reusable code, so any method that has the potential to jeopordise these aims should always be used with a great deal of caution.

  • Object Oriented Programming 2
  • Object Oriented Programming 3
  • Object Oriented Programming 4
  • Object Oriented Programming 5
  • Object Oriented Programming 6
  • Object Oriented Programming 7
  • Object Oriented Programming 8

Filed Under: Object Oriented Programming

Latest Articles

Do You Need a VPN When Trading Cryptocurrency?

There’s no doubt that the biggest global industries in 2023 are tech-driven, while there remains a significant crossover between many of these sectors. For example, a growing number of cryptocurrency traders regularly utilise a VPN, in order to encrypt their web traffic and data and minimise the … [Read More...]

New Software and GPS Tools Help Parents Monitor their Children

More parents are using technology to keep their children safe. One survey from Pew Research in 2016 showed that 30% of parents use technology to block access to harmful online sites or monitor their online activities. That figure has risen significantly in recent years. Currently, 50% of parents … [Read More...]

PC Technicians Seek New Ideas for Customer Outreach in Evolving Market

People are more dependent on PC tech repair services remains fairly high. According to research from IBIS World, the market for these services is estimated to be worth $18.7 billion. Unfortunately, demand for these services is starting to temper. IBISWorld reports that the market size is … [Read More...]

Gaming Laptop Security Guide: Protecting Your High-End Hardware Investment in 2025

Since Jacob took over PC Tech Guide, we’ve looked at how tech intersects with personal well-being and digital safety. Gaming laptops are now … [Read More...]

20 Cool Creative Commons Photographs About the Future of AI

AI technology is starting to have a huge impact on our lives. The market value for AI is estimated to have been worth $279.22 billion in 2024 and it … [Read More...]

13 Impressive Stats on the Future of AI

AI technology is starting to become much more important in our everyday lives. Many businesses are using it as well. While he has created a lot of … [Read More...]

Graphic Designers on Reddit Share their Views of AI

There are clearly a lot of positive things about AI. However, it is not a good thing for everyone. One of the things that many people are worried … [Read More...]

Redditors Talk About the Impact of AI on Freelance Writers

AI technology has had a huge impact on our lives. A 2023 survey by Pew Research found that 56% of people use AI at least once a day or once a week. … [Read More...]

11 Most Popular Books on Perl Programming

Perl is not the most popular programming language. It has only one million users, compared to 12 million that use Python. However, it has a lot of … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

ASUS P8Z77-V PRO

$229 - ASUS P8Z77-V PRO is an Intel 7 series mother board. Socket H2 (LGA1155) At this time the product has 2 great reviews on Tigerdirect and 1 … [Read More...]

How to Turn on Firewall in Windows 7

Keeping your computer secure is important if connected to the Internet. One of the best forms of protection you can implement is a firewall. If you … [Read More...]

Online Gambling Niche — State, Trends, Prospects

In 2021, people continue to stay at home, relaxing with various gadgets, and this is a great opportunity for affiliates to extend their gambling … [Read More...]

[footer_backtotop]

Copyright © 2025 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors