SOLID : Open / Closed Principle

The Open / Closed Principle focuses on one basic requirement, the classes should be Open for extensions, but closed for modification. The better way to explain the principle would be to first express the issue in hand. Consider the below class. The class itself looks good, but what if in future one needs to add … Continue reading SOLID : Open / Closed Principle

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

Composite Primary Key using Data Annotations

When developing domain classes in Entity Framework using Code First Approach, the default code conventions creates a primary key of a property named "ID" or <ClassName>ID. But if you wanted to use another property as your primary key , you can use DataAnnotations and decorate the property using "Key" attribute. What is more interesting is … Continue reading Composite Primary Key using Data Annotations

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)

Evil Code 0002 Optional Parameter Vs Method Overloading

Again one of those things which looks so simple, but could drive one mad during debugging. Much before Optional Parameters came in, C# developers used to depend on Method Overloading for mimicking Optional Parameters. Consider a scenario where both exists, what would be the output ? The output would be : The reason behind this … Continue reading Evil Code 0002 Optional Parameter Vs Method Overloading