Showing posts with label Inheritance. Show all posts
Showing posts with label Inheritance. Show all posts

Monday, 15 April 2013

Group Activity - Inheritance



A Player has the following attributes: 

  • Name
  • Health
  • Strength
  • intelligence
  • Location
    • X coordinate
    • Y coordinate
  • Inventory
    • a collection of InventoryItem's - each InventoryItem has the following attributes
      • ID
      • Price
      • Weight.
A Weapon is a type of InventoryItem. It has a single int attribute: DPS. 
  • An object of Weapon type may be constructed with or without providing a value for this attribute. 
    • A Gun is a type of Weapon. It has a single int attribute: ammoCount. A value for this attribute must be provided in the constructor. 
    • A Stick is a type of Weapon. It has a single int attribute: stickLength. A value for this attribute must be provided in the constructor.


A Tool is a type of InventoryItem. It has a single int attribute: numberOfUses. 

  • An object of Tool type may be constructed with or without providing a value for this attribute. 
    • A Key is a type of Tool. It has a single String attribute: keyName. A value for this attribute must be provided in the constructor. 
    • A Mirror is a type of Tool. It has a single String attribute: mirrorName. A value for this attribute must be provided in the constructor.


Original Post Jul 29th 2012

Inheritance Scenario: XYZ



yClass is a type of xClass. 

A XClass has 3 int states, x,y & z. 

An object of the xClass may be created by providing a value for all 3 of these states and also by providing only x & y. 

The yClass has 2 int states, a & b. 

An object of the yClass may be created by providing a value for a, or values for both a & b. 

The zClass is a type of yClass and has 1 int state called c. 

An object of the zClass may be created with or without supplying a value for c.

Original Post Jul 23rd 2012