Within my logic layer I have the need to check permissions for a wide variety of actions. Some actions are generic but some are highly specialized. Each action has a corresponding permission hierarchy that is evaluated prior to performing the action. I have been tossing around architecture ideas in my head but haven't reached a solid one that I think will be extensible, simple and elegant.
The current code looks something like this:
public class LogicObject
{
public void Add()
{
Check Add Permission
Perform
}
public void Update()
{
Check Update Permission
Perform
}
}
The problem with this architecture is that, first it isn't really all that extensible, and second it doesn't allow me to check the permission without performing the action.
Another idea I had was to have something like this:
public class AddAction : IAction
{
public bool IsPermitted;
public void Perform();
}
public class LogicObject
{
public IAction AddAction {get { return new AddAction(); } }
}
I like this architecture better but I am not quite set on it. It seems a bit hokey. I can't imagine that this type of architecture is unique. What are some examples of a better way of doing this?