What is the need for State Pattern in C#?If you want
to change behavior of an object when there is a change in its internal
state then you can do it by implementing State pattern in your C# application.
Here is a
code sample for it: Now you can
create a new class and inside its Main method, you can create an instance
of contextClass (by calling constructor passing either instance of derivedClass1
or derivedClass2) and call the raiseRequest method, every call to this
method toggles the objects state.
|