What Is State Pattern C#?
State Pattern in C# allow an object to alter its behavior when its internal state changes.
The State pattern, can be seen as a dynamic version of the Strategy pattern. When the state inside an object changes, it can change its behavior by switching to a set of different operations.
You’ve got along ASP.NET project ahead. You’re trying to wrap your head around all tasks at hand - infrastructure, business logic, admin panel, integrations. On top of that, there’s a long list of ‘could have’ type of features that the team would like to implement if time and resources allow.
One of them is adding the ability to send email in ASP.NET C# that you’ve been postponing for a while. After all, it’s such an obvious feature that might as well be left for the very end, when almost everything is up and running. Before your project goes live, you will need to validate your email workflows anyway and probably you don’t want to stay extra hours just before the launch to do so.
While sending emails with C# is not rocket science, we strongly recommend thinking about it sooner rather than later. To make it easier to start, we’ve covered the first steps with the various code samples. Let’s start!
What Is Strategy Pattern C# ?
The Strategy pattern in C# lets the algorithm vary independently from clients that use it.
There may be different algorithms (strategies) that apply to a given problem. If the algorithms are all kept in the client, messy code with lots of conditional statements will result.
Strategy pattern defines a family of algorithms, encapsulate each one, and make them interchangeable.
The Strategy pattern enables a client to choose which algorithm to use from a family of algorithms and gives it a simple way to access it.
The Mediator pattern in C# enables objects to communicate, without knowing each other’s identities. It also encapsulates a protocol that objects can follow.
You can think of a Mediator object as a kind of a coordinator; that handles traffic between appropriate parties based on its own logic.
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.