I couldn't help but share this. There couldn't be a better way to summarize the unwritten rules of TDD, than the one wrote by Uncle Bob in his famous book 'Agile Principles, Patterns and Practices in C#''. Don't write any production code until you have written a failing unit test. Don't write more of a … Continue reading 3 Rules for TDD
Tag: Best Practices
Why avoid Conversion Operators
No doubt that the Conversation Operators makes developers life easier by bring in a kind of substitutability, but it comes with a price. If not properly designed/used, it could result in subtle errors that can be easily ignored. Consider the following code. We have a class called Car, which exposes a single property - MakerName. We … Continue reading Why avoid Conversion Operators
Design Patterns : Template Method
The purpose of a Template Method Pattern is to define the skelton of an algorithm, while deferring the exact steps to sub classes. There is plenty of literature on the internet detailing the pattern, so we will skip it and head right to the code. As always, lets begin by defining the contract interface, in … Continue reading Design Patterns : Template Method
Design Patterns : Chain of Responsibility
The intend of Chain of Responibility Pattern is to avoid coupling the sender of a request to its reciever by giving more than one object change to handle the request. Let's try to mimic the execution of classical Waterfall Model with CoR. Let's begin by declaring the contract interface. And our sub classes. The final … Continue reading Design Patterns : Chain of Responsibility
Design Patterns : Fascade Pattern
Fascade, name being an analogy to an architectural fascade, intends set the tone for the entire functionality by providing a simplified yet effective interface wrapping away the complex, pooly designed collection of APIs. Wrong Code Consider following set of Classes. The Client Code could be As you can see, the Client class is invoking … Continue reading Design Patterns : Fascade Pattern
Patterns,Principles and Programming.
Have been thinking about putting together a collection of Jump Start Tutorials on some core concepts on Programming, finally getting everything together Design Patterns GOF: Adapter Pattern GOF: Strategy Pattern GOF: Singleton Pattern (Lazy) GOF: Fascade Pattern GOF: Chain Of Responsibility Pattern (CoR) GOF: Template Method GOF: Null Object Pattern GOF: State Pattern GOF: Decorator … Continue reading Patterns,Principles and Programming.
Design Patterns : Strategy Pattern
If there is one thing that is constant in every software development projects, then it has to be CHANGE. Requirements evolve overtime and you might end up with fairly different set of requirements that you initially started of. As developers one has to be aware of the possibility of change and design applications that are flexible … Continue reading Design Patterns : Strategy Pattern
Design Patterns : Adapter Pattern
There is already a large amount of literature on the Internet which discusses Adapter Pattern. However, the purpose of article is to showcase the implementations of the Adapter Pattern, rather than discussing the application of the pattern. In this post, adapter class is implemented using 1. Inheritance 2. Dependency Injection 3. Generics Consider your old … Continue reading Design Patterns : Adapter Pattern
SOLID : Single Responsibility Principle
While OOPs is rich with features like inheritance, polymorphism, encapsulation and overloading enabling developers to extract more from modern day programming languages like C#, it is equally important to understand when to use these features based on design principles. SOLID, is a set of 5 principles which when properly applied intend to guide a programmer … Continue reading SOLID : Single Responsibility Principle
Singleton using Lazy(T)
Singleton Design Pattern is probably the simplest and most straightforward design pattern. So instead of explaining further, let me get to the code. The whole idea behind the above implementation of Singleton is to make use of the Lazy(T) class provided by Framework 4.0 and provide a lazy initialized version of the pattern, in addition … Continue reading Singleton using Lazy(T)