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

How To Install a New Sound Card In Your PC

If you're planning on using a joystick or MIDI device you're going to need access to two adjacent PCI slots. Fit the sound card and joystick/MIDI bracket as illustrated, connecting the latter to the associated connector on the sound card using the cable provided. When installing the sound … [Read More...]

Safely Overwrite the Deleted Files: Cipher and Eraser

When someone deletes files on their PC, Windows users knew it wasn't really gone and it can be recovered. The deleted files are still there on your hard drive until they’re overwritten with a new data. Using applications such as CCleaner or Eraser can truly wipe the data and give you free space … [Read More...]

Graphic Card Memory

The memory that holds the video image is also referred to as the frame buffer and is usually implemented on the graphics card itself. Early systems implemented video memory in standard DRAM. However, this requires … [Read More...]

Tips on How to Land a Remote Job in Cyber Security

The demand for skilled cyber security professionals is growing as well as a number of threats and risks. Any company needs an expert or team to … [Read More...]

Video Tutorials for Anyone Wanting to Learn About Big Data

Did you know that we create about 2.5 quintillion bytes of data every single day? There is no denying the fact that big data is changing our world in … [Read More...]

Video Tutorials to Help Canva Users Shorten their Learning Curve

Canva is a very popular design software that is used by over 55 million designers. It is a robust application, but it can be tricky for beginners to … [Read More...]

Great Videos to Learn About Cricut Design Space

Cricut Design Space is one of the best digital design applications for people trying to create projects for Cricut projects. You can create a lot of … [Read More...]

Great Videos on Dangerous Computer Viruses

Computer viruses are obnoxious programs that can wreak havoc on even the most sophisticated machines. The good news is that people will be better … [Read More...]

Best Creative Commons Videos on Learning Adobe Illustrator

Adobe Illustrator is one of the most popular design tools available. The tool has been around since 1987 and is used by over 90% of the world's … [Read More...]

Guides

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

Recent Posts

Driver Scanner Review

[starreviewmulti id=6 tpl=20] The installation of Driver Scanner 2012 as with previous versions went very smooth. The interface was easy to use, … [Read More...]

Transferring Image Files from Your Cell Phone Without Cables or Email

You don't have a cable available to transfer the photos from your cell phone to your computer? You don't feel comfortable sending them through your … [Read More...]

The Potential Power of DDR3 Memory

DDR3 SDRAM which stands for Double Data Rate Type Three Synchronous Dynamic Random-Access Memory is the higher version of DDR2 and predecessor of … [Read More...]

[footer_backtotop]

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