Status Quo

In 2007 there was a movement in the .NET community dubbed “ALT.NET”.  A community was formed by individuals who believed there to be a “better” way from the tooling, frameworks, practices and principles provided by Microsoft.  The initial release of Linq to Entities (Entity Framework) was really a starting point for discussion since it did not support POCO’s and was not persistence ignorant.

ALT.NET was about challenging the status quo.  Although some might not be familiar with with the ALT.NET movement, you can thank it for helping the common practice of: Inversion of Control (Dependency Injection), Persistence Ignorant ORM’s, and SOLID principles.

So what happened to the community?  Was it a failure since it is no longer as active?  Or was it a success because many of the alternatives are now the “norm”?  I believe it to be both.

We need to continue challenging the status quo.  Individually and as a community.  Innovation and process improvement can only come from alternative thinking.  Have pride for the software you develop (Manifesto for Software Craftsmanship) and improve upon the existing practices.

Open/Closed Principle Violation

Before I post too many SOLID principle posts, let me prefix by saying that I strongly believing that following SOLID principles as guidelines will lead to writing better Object Oriented code.

Back to Open/Close Principle

Software entities like classes, modules and functions should be open for extension but closed for modifications.

Out of all the SOLID principles, I’ve found this one to causes the most confusion and is the hardest to identify for developers.  When following any of the SOLID principles, they all have a bit of cross over that help you identify when violating one of them.  Violating Open/Close principle usually means you are also violating Single Responsibility.

Here are a few smells/tips to for identifying when you might be violating Open/Closed principle:

  • Conditional Code
  • Multiple unit tests due to multiple execution paths
  • Violation of Single Responsibility
[code lang=”csharp”] // Something smells in here…
public int GetSpeed()
{
int speed = 0;

if (_type is Bike)
{
speed = 10;
}
else if (_type is Car)
{
speed = 70;
}
else if (_type is Jet)
{
speed = 300;
}

return speed;
}
[/code]