Hello!
Here I have one base klass and three subklasses.
I Just want to have your opinion about the design of these klasses.
I don't think that my design is good.
I think that I instead should not have done the base class abstract it is
so now but that is wrong I think. The base class should be concrete
Define then method fetchWeaponName, fetchAllowedAnimal and getPrice in the
base class which mean that these can be removed from the subclasses. Change
the access specifier defined as protected to private in the base class.
virtual string fetchWeaponName() const
{ return Weapon::weaponName; }
string fetchAllowedAnimal() const
{ return Weapon::allowedAnimal; }
virtual int getPrice() const
{ return Weapon::price; }
//Tony
#ifndef WEAPON_H
#define WEAPON_H
#include "common.h"
class Weapon
{
public:
Weapon(int pris, string vapen_namn, string djur) :
price(pris),weaponName(vapen_namn), allowedAnimal(djur) {}
Weapon() {}
virtual ~Weapon() {}
virtual string fetchAllowedAnimal() const = 0;
virtual string fetchWeaponName() const = 0;
virtual int getPrice() const = 0;
protected:
int price;
string weaponName;
string allowedAnimal;
};
#endif
#ifndef MOUSERIFLE_H
#define MOUSERIFLE_H
#include "common.h"
class MooseRifle : public Weapon
{
public:
MooseRifle(int price,string weapon_name,string animal) : Weapon(price,
weapon_name, animal)
{}
MooseRifle()
{}
virtual ~MooseRifle()
{}
virtual int getPrice() const
{ return Weapon::price; }
virtual string fetchWeaponName() const
{ return Weapon::weaponName; }
string fetchAllowedAnimal() const
{ return Weapon::allowedAnimal; }
private:
};
#endif
#ifndef WINCHESTER_H
#define WINCHESTER_H
#include "common.h"
class Winchester : public Weapon
{
public:
Winchester(int price,string weapon_name,string animal) : Weapon(price,
weapon_name, animal)
{}
virtual ~Winchester()
{}
virtual string fetchWeaponName() const
{ return Weapon::weaponName; }
virtual int getPrice() const
{ return Weapon::price; }
string fetchAllowedAnimal() const
{ return Weapon::allowedAnimal; }
private:
};
#endif
#ifndef SHOTGUN_H
#define SHOTGUN_H
#include "common.h"
class Shotgun : public Weapon
{
public:
Shotgun(int price,string weapon_name,string animal) : Weapon(price,
weapon_name, animal)
{}
virtual ~Shotgun()
{}
string fetchWeaponName() const
{ return Weapon::weaponName; }
virtual int getPrice() const
{ return Weapon::price; }
string fetchAllowedAnimal() const
{ return Weapon::allowedAnimal; }
private:
};
#endif