I have an object with some methods:
public class Foo
{
public void Bar() { }
public void Baz() { }
}
These methods cannot be executed unconditionally, there is some validation to be done. I'd also like to expose these conditions to a client (user) in some way.
I could do this with a collection of enum values:
public enum FooAction
{
Bar,
Baz
}
public class Foo
{
public void Bar() { if (GetAvailableActions().Contains(FooAction.Bar)) }
public void Baz() { if (GetAvailableActions().Contains(FooAction.Baz)) }
public IEnumerable<FooAction> GetAvailableActions() { }
}
I could also do this with boolean functions:
public class Foo
{
public void Bar() { if (CanBar()) }
public void Baz() { if (CanBaz()) }
public bool CanBar() { }
public bool CanBaz() { }
}
I've tried to come up with a reason to favour one over the other, but I can only think of a possible performance benefit depending on how much input data these methods would have in common. And likely said performance benefit would be negligible.
Are there any real-world problems that could occur with one solution and not with the other? Or does the whole thing boil down to personal preference?
I've added the [tag:domain-driven-design] and [tag:cqrs] tags because it's in the context of a DDD/CQRS architecture, but I'm not sure if that matters for this problem.