DEV Community

Cover image for Inheritance, as applied to an RPG
Nathan Englert
Nathan Englert

Posted on

Inheritance, as applied to an RPG

This is the second article in a series I'm doing called DevBits. These are mini-articles that show how object-oriented programming concepts can be applied.


You’re making an RPG.

You have a Character (class) who has health (field).

A Character can move() or attack() (methods).

A Player (child class) is a type of Character, but also has experience (field).

An Enemy (child class) is a type of Character, but also has loot (field).

Player and Enemy both share the same fields and methods from Character, but can have any additional fields of their own.

This is inheritance.

Cover image was created by Buch.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more