I am thinking of creating some classes using a one-time use pattern defined by the following functions:
- Instances are used to perform some tasks.
- The instance will execute the task only once. Attempting to call the
execute method twice will throw an exception. - Properties can be changed before calling the
execute method. Calling them subsequently will also raise an exception.
A minimalist implementation might look like this:
public class Worker { private bool _executed = false; private object _someProperty; public object SomeProperty { get { return _someProperty; } set { ThrowIfExecuted(); _someProperty = value; } } public void Execute() { ThrowIfExecuted(); _executed = true;
Questions:
- Is there a name for this?
- Pattern or anti pattern?
source share