Programming Tips, Tricks, Rants and Raves
Dependency Inversion Principle is a Must for Object-Oriented Programming

Traditional procedural programming creates a dependency structure in which policy depends on detail. This is unfortunate, since the policies are then vulnerable to changes in the details. Object-oriented programming inverts that dependency structure such that both details and policies depend on abstraction, and service interfaces are often owned by their clients.

Indeed, this inversion of dependencies is the hallmark of good object-oriented design. It doesn’t matter what language a program is written in. If its dependencies are inverted, it has an OO design. If its dependencies are not inverted, it has a procedural design.

The principle of dependency inversion is the fundamental low-level mechanism behind many of the benefits claimed for object-oriented technology. Its proper application is necessary for the creation of reusable frameworks. It is also critically important for the construction of code that is resilient to change. Since abstractions and details are isolated from each other, the code is much easier to maintain.

Robert C. Martin and Micah Martin
Agile Principles, Patterns, and Practices in C#
Prentice Hall 2006

Overcomplicating the Simple – String.IsNullOrWhiteSpace

Today’s overcomplicating the simple covers a new framework method that was introduced in .Net 4.0. This method is very simple, however it seems that not many people know about it, or they are creatures of habit and still prefer the old way.

This new method is String.IsNullOrWhiteSpace and it’s very similar to String.IsNullOrEmpty, however in addition it returns true when the string being checked is white space.

Here’s a common example of where this new method could have been used:

private void Foo( string bar )
{
  if( string.IsNullOrEmpty( bar ) )
  {
    throw new ArgumentException(
      "Parameter cannot be null or whitespace", "bar" );
  }
  else if( bar.Trim().Length == 0 )
  {
    throw new ArgumentException(
      "Parameter cannot be null or whitespace", "bar" );
  }
  ....
}

Continue Reading »

How to Inspire Others to Produce Clean Code

Are you disappointed with the quality of source code that is being produced by your team? Wish there was something you could do? With a bit of hard work, perseverance, and people skills you can start influencing the team towards better programming practices.

In order to influence your fellow developers, you will need to build a vision that they will accept. The process of building this vision will be a difficult. You will need to navigate multiple hurdles.

Hurdle 1
You need to define what you mean by the term “clean code”. If you’ve been following my blog for any time, you should have an idea what I think clean code means. I was introduced to this term by Uncle Bob’s book similarly titled book, Clean Code. In summary clean code means that we pay careful attention to the details of software to make the code readable and maintainable: good names, good comments, small methods, eliminated dead code, and basic object-oriented principles.

Continue Reading »

Design Patterns vs. Anti Patterns

Design Patterns

Design patterns are proven solutions to particular types of problems, and help us structure our own applications in ways that are easier to understand, more maintainable, and more flexible.

Design patterns help you recognize and implement GOOD solutions to common problems.

Anti Patterns

Anti-patterns are the reverse of design patterns: they are common BAD solutions to problems. These dangerous pitfalls should be recognized and avoided.

Anti patterns are about recognizing and avoiding BAD solutions to common problems.

Brett D. McLaughlin, Gary Pollice, Dave West
Head First Object-Oriented Analysis and Design
O’Reilly Media, Inc 2007

Get Updates

Make sure you don't miss new posts. Subscribe via RSS or email today.

Email:  
Resource Articles