samedi 25 novembre 2017

What's the best design for extra data on behaviour class?

I have a game where the player can finish some tasks.

I have separated the behaviour part of the task to its ORM part. Eventually a copy of the task is being saved somewhere on the player's document (doesn't matter where for this specific question).

The problem is, I am not sure where to put the extra information that I send to the client that is not necessary for the behaviour itself, but it is needed to show the player information regarding the task itself.

This is my task interface:

interface ITask
{
    /**
     * @param Player $player
     */
    public function init(Player $player);

    /**
     * @param PlayerAction $action
     */
    public function progress(PlayerAction $action);

    public function reset();

    /**
     * @return bool
     */
    public function isComplete();
}

This is my abstract task:

abstract class BaseTask implements ITask
{
    /**
     * @var int
     */
    public $id;

    /**
     * @var int
     */
    protected $currentValue;

    /**
     * @var int
     */
    protected $targetValue;

    public function __construct($targetValue)
    {
        $this->currentValue = 0;
        $this->targetValue = $targetValue;
    }

    /**
     * @param int
     */
    public abstract function setCurrentValue($current);

    /**
     * @return  int
     */
    public abstract function getCurrentValue();

    /**
     * @return int
     */
    public abstract function getID();

    /**
     * @param int
     */
    public abstract function setID($id);

    /**
     * @return int
     */
    public abstract function getTargetValue();

    /**
     * @param int
     */
    public abstract function setTargetValue($target);

    /**
     * @return boolean
     */
    public function isComplete()
    {
        if ($this->getCurrentValue() >= $this->getTargetValue())
        {
            return true;
        }

        return false;
    }
}

Now I need to decide how where to put the extra data, e.g description, title, theme etc...

  1. I thought about two options: I can just put it on the base task itself, but then what happens if I don't need it? I just leave it blank? feel like the wrong place for me.
  2. I could create a wrapper class that will hold the task, but then I will need to always call the wrapper to get to the task, and it feels kind of wrong.

Looking for alternative suggestions.

Aucun commentaire:

Enregistrer un commentaire