I have some actions... View, Edit, Checkout, etc. Business logic dictates that if a document is already checked out, all Views turn into Edits.
is there a neat OO way to do something like this:
class Action
{
public:
Document document;
virtual void execute();
};
class View, Edit, Checkout : public Action;
View::execute()
{
if (document.isCheckedOut)
{
delete this;
this = new Edit;
this->execute();
}
/* execute view */
}
update: what do you guys think of this:
class Action
{
public:
static int type;
Document document;
virtual void execute();
static Action* construct(int type, Document document) = 0;
private:
Action();
};
class View, Edit: public Action;
Action* View::construct(Document document)
{
if (document.isCheckedOut)
return new Edit(document);
return new View(document);
}
Action* Edit::construct(Document document)
{
return new Edit(document);
}
void onViewButton(Document document)
{
Action *action = View::construct(document);
action->execute();
delete action;
}