pctechguide.com

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

Object Oriented Programming – Examples

Earlier we developed a class inheritance tree for some game characters in a maze game, but we need to design another class, or class hierarchy, for the maze. Since we want the mazes to have different levels of difficulty, each level of maze will require slightly different functions.

We can say that each maze, of any level, will be a grid, with each square of the grid being defined as the size of a single game character move. The grid will be stored in a two dimensional array, in which each grid square is represented with a 0 for no wall, or a 1 for wall. There will be one exit defined in the grid with a -1. The maze itself will be randomly created with a function, as will the start location for both the monster and the player character.

The

At first glance it appears that our derived complexMaze class has only one function, but it has actually inherited all the member functions and data of the base class maze. In that light, you can see that in fact it’s single member function is actually a repeat of the base class’s function, createMaze(). The new createMaze() function will use a completely different algorithm in order to create a more difficult maze. When a derived class redefines a base class’s function in this way it is called overriding, and it is the basic essence of polymorphism.

Polymorphism can cause headaches if programmers are not aware of the version of the function they are using. In this example, if an object is created of type maze and the function createMaze() is called, it will use the version of createMaze defined in the base maze class. If however the function createMaze() is called by an object of type complexMaze, then the version of the function called is the one defined in the complexMaze class. In a very deep inheritance tree it is at least possible that a function may be overridden many times, and a programmer has to be very careful to know exactly which function is going to be called.

It’s also important to note that this is by no means the only solution to the problem. For instance, parameters passed to the maze function createMaze() could just as easily govern the complexity of the maze created. However, there may be other compelling reasons for developing a derived complex maze class, reasons that the project designer must weigh up when creating the class hierarchy. There will often be several different solutions available, and sometimes it may be worth using inheritance and polymorphism, whilst at other times using conditional programming branches might be better. The ability to make these often crucial decisions well and with confidence, like most things, comes with practice and experience.

  • 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

PC Tools File Recover Review

PC Tools File Recover PC Tools File Recover is a very good product for data recovery. The price is great and includes 3 licenses with the package. It has even made our top 5 list on data recovery products. ยป Download PC Tools File Recover Here Program: PC Tools File Recover … [Read More...]

Machine Learning Advances Lay Foundation for More Effective Presentations

Machine learning is setting new standards for communication. The global market for machine learning technology was estimated to be worth $1.4 billion in 2017. The market is projected to grow 43.6% between 2017 and 2022. One of the ways that machine learning is changing the future of … [Read More...]

WinDirStat

Use WinDirStat to Clean Up Hard Drive

Today's hard drives are large and can store tons of files, pictures, videos, etc. But, even with all this space there still may be a time when you need to clean up because the hard drive is filling up. There are the obvious places to check like the Recycle Bin or use the Disk CleanUp tool. But, … [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

Remove InstantRadioPlay Toolbar

InstantRadioPlay Toolbar is another problematic toolbar that promises to offer useful features. It will allow you to listen to the radio online … [Read More...]

Pentium Smithfield

Essentially, the Smithfield core is no more than a pair of 90nm Prescott 1M dies bound together. Each core has its own … [Read More...]

i965 Chipset

In June 2006, Intel launched its 965 Express chipset, the formerly codenamed Broadwater, developed for use with platforms which feature the its … [Read More...]

[footer_backtotop]

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