pctechguide.com

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

Object Oriented Programming 5

To illustrate putting together an object oriented (OO) class hierarchy design, let’s take a look at a simple maze game. We’ll be creating an OO design, but we’re not going to select a programming language at this stage. We’ll see how we can analyse the problem from an OO perspective, and produce a workable OO design solution that can be translated into implementation code.

Our simple game involves a two dimensional maze and two moving objects. The moving objects are the player’s character and a monster that chases the player around while they try to solve the maze. For our OO design, the key here is that, although these two objects have clear differences, initially we’re only interested in what they have in common.

During the game the player’s character and the monster both have to have their screen position stored, and this is best held as a two dimensional coordinate x and y. The point class is a very common class for storing coordinates, and one we’ll use in our design. We also want to know whether or not the characters are alive in the game. To cover these similarities, we can create a class that covers both the game characters, as follows.

We’re using Unified Modelling Language (UML) notation in our class modelling. UML is commonly used in object oriented design, and ArgoUML is a free Java tool you can use to produce your own UML diagrams.

The

Notice that gameCharacter has not been derived from the class point, but has included a data member currentLocation which is of type point. Now we’ll get on to inheritance as we start to think about the differences between the game characters.

Remember that a class doesn’t just have data members, but also methods, and the methods for the game objects concerning movement are very different. The player character is going to be moved in response to player commands, while the monster will need an Artificial Intelligence (AI) game function to make it move in pursuit of the player.

There are also different data requirements. For the player, we want to keep a score, and what level of maze they’ve reached. For the monster, we at least want to have a speed variable, so that we can have it move faster or slower.

A

Note that there are a number of functions that have been ommitted from the class designs, particularly how to get and set the values of the various class data members, assuming they are private class members, but the basics are there. With thought, this class tree can be extended in all sorts of ways. Various game characters might be derived from the gameCharacter class, or from the monster class, whichever makes most sense. You can see that using inheritance each derived class provides greater and greater specialisation, but that the base class provides a foundation of reusable code to build upon.

Next we’ll take a look at times when a class may be designed that has more than one bass class, known as multiple inheritance.

  • 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

FireWire 800 Interfaces

In early 2001 the battle between IEEE 1394 and USB advanced another step with the 1394 Trade Association's approval of specifications for a faster version of IEEE 1394, called IEEE 1394b. The new standard is backwards compatible - special … [Read More...]

Make Twitter Powerful for You With These 10 Tricks

Social media has become an effective for of marketing for businesses if it is done the right way. However, many businesses struggle with how to use this powerful medium. This article will provide a few simple tricks a business can use to make Twitter a powerful weapon in their marketing … [Read More...]

CDR-RW UDF File System

The ISO 9660 standard, which has been applicable for CD-ROMs since their inception, has certain limitations which make it inappropriate for DVD, CD-RW and other new disc formats. The UDF (Universal Disc Format) ISO 13346 standard is … [Read More...]

Importance of Inbound Marketing in the Digital Age

A couple of months ago, Zacks reported that Hubspot was starting to make some major changes to its inbound marketing strategy. They talk a lot about … [Read More...]

Damage Control Strategies for Resolving Online PR Crises

Last July, Astrologer faced a major crisis after its CEO went viral at a ColdPlay concert when having an affair. This was just one of the many times a … [Read More...]

AI is Not Killing Computer Jobs Like Doomers Projected

There is no denying the reality that AI technology has played a massive role in disrupting our lives. A growing number of people claim that AI … [Read More...]

Everything You Need to Know About Sourcing Circuit Boards From U.S. Suppliers

In This Article This article includes: Why Source PCBs From the United States?How to Get a Quote From a U.S.-Based PCB ManufacturerThe Top U.S. … [Read More...]

Top Taplio Alternatives in 2025 : Why MagicPost Leads for LinkedIn Posting ?

LinkedIn has become a strong platform for professionals, creators, and businesses to establish authority, grow networks, and elicit engagement. Simple … [Read More...]

Shocking Cybercrime Statistics for 2025

People all over the world are becoming more concerned about cybercrime than ever. We have recently collected some statistics on this topic and … [Read More...]

Guides

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

Recent Posts

VCR to DVD Conversion – Video Capture Cards and PC Hardware

There are a number of important hardware factors when transferring your VCR to digital video. For most people a balance needs to be struck when … [Read More...]

Website Builders Make Web Design Available to Everyone

The Internet is a powerful communication medium. It gives people the power to share their ideas, passions or business with millions of people. And, it … [Read More...]

Guide to Western Digital’s GreenPower hard drive technology

Western Digital's release of its GreenPower hard drive technology signalled another significant move by a major manufacturer into the … [Read More...]

[footer_backtotop]

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