MVC: Custom Validation

Please see my other MVC articles. Using Custom Validation within a View While MVC provides many robust attributes within a Model to satisfy many validation scenarios, some situations exist which require custom logic to validate a user’s input. This article will illustrate how to implement your own routines to validate user input. First, create a…

C# 4.0 Parameterless Functions

Please see my other C# articles. Integrating flexibility into class behavior. When designing class behavior, knowing ahead of time how that function will need to be used is sometimes difficult. For example, when defining the function signature how do you know in what order the parameters should be arranged and what if that makes a difference to…

TDD: Testing with Stub Methods

Please see my other Test Driven Development articles. Adding flexibility to return values using Stub methods. Continuing on my “Testing with Dummy objects” article, you might have noticed a limitation with regards to the return value – only one was allowed. In situations where multiple return values are needed, Stub methods provide an alternative. In…

TDD: Refactoring with Polymorphism

Please see my other Test Driven Development articles. Using polymorphism to refactor SRP violations. Single Responsibility Principle (SRP) violations are one of the most common issues found in code. Either the class or its behavior is attempting to fulfill more than one primary purpose. In this example, I will illustrate how polymorphism provides a powerful…

TDD: Mocking with Dummy Objects

Please see my other Test Driven Development articles. Using custom objects in place of a mocking framework. When it’s desired to avoid the overhead of a mocking framework and its functionality isn’t required, developers may elect to provide their own dummy objects instead. In this article I will illustrate a simple example of writing my…

TDD: Assets

Please see my other Test Driven Development articles. Leveraging overloaded Assert() methods to enhance test methods. Continuing from my TDD: Mocking with Dummy objects article, I wanted to illustrate some examples of other Assert() methods available for use to enhance testing results. As illustrated in my last example, you may just utilize the traditional Assert.AreEqual()…

Design Patterns: Singleton

Please see my other Design Pattern articles. Ensuring single instance use during instantiation. Every so often in development, a business rule dictates that instantiation of a certain type produce only one instance during the lifetime of the application. The Singleton design pattern, one of the Creational Patterns, ensures that regardless of many instantiations of a…

Design Patterns: Service Locator

Please see my other Design Pattern articles. Completing the IoC Design Pattern. In my Design Patterns: Inversion of Control article, I illustrated how to decouple classes from having dependencies – the CustomerPayment class contained a dependency on the IPayment interface. Any class which has intimate knowledge of another is tightly-coupled to that class. By implementing…

Design Patterns: Inversion of Control

Please see my other Design Pattern articles. Providing flexibility into the domain by abstracting implementation. Using abstraction between concrete and class implementation, avoid tightly-coupled classes, which leads to changes in once class to ripple throughout your application. One method of doing this is the Inversion of Control design pattern which allows the class calling the…

Design Patterns: Factory

Please see my other Design Pattern articles. Providing flexible object-instantiation. In this example, I’ll illustrate a method by which a SalesAssociate object may be instantiated that is more flexible than the traditional way – using a constructor. Instead I’ll implement a factory design pattern to create the instance. There are two advantages to this approach:…