Architecture and patterns

http://dotnetcodr.com/architecture-and-patterns/

Architecture and patterns

Read more of this post

SOLID design principles in .NET: the Open-Closed Principle

http://dotnetcodr.com/2013/08/15/solid-design-principles-in-net-the-open-closed-principle/

Introduction

Now it’s time to move to the letter ‘O’ which stands for the Open-Closed Principle (OCP). OCP states that classes should be open for extension and closed for modification. You should be able to add new features and extend a class without changing its internal behaviour. You can always add new behaviour to a class in the future. At the same time you should not have to recompile your application just to make room for new things. The main goal of the principle is to avoid breaking changes in an existing class as it can introduce bugs and errors in other parts of your application.

How is this even possible? The key to success is identifying the areas in your domain that are likely to change and programming to abstractions. Separate out behaviour into abstractions: interfaces and abstract classes. There’s then no limit to the variety of implementations that the dependent class can accept.

Read more of this post

Simplifying the Liskov Substitution Principle of SOLID in C#

http://www.infragistics.com/community/blogs/dhananjay_kumar/archive/2015/06/30/simplifying-the-liskov-substitution-principle-of-solid-in-c.aspx

The Liskov Substitution Principle says that the object of a derived class should be able to replace an object of the base class without bringing any errors in the system or modifying the behavior of the base class.

In short: if S is subset of T, an object of T could be replaced by object of S without impacting the program and bringing any error in the system. Let’s say you have a class Rectangle and another class Square. Square is as Rectangle, or in other words, it inherits the Rectangle class. So as the Liskov Substitution principle states, we should able to replace object of Rectangle by the object of Square without bringing any undesirable change or error in the system.

Read more of this post

2,000 Things You Should Know About C#

http://csharp.2000things.com/index/

 

Add/Attach and Entity States

https://michye.wordpress.com/?p=101&preview=true

This topic will cover how to add and attach entities to a context and how Entity Framework processes these during SaveChanges. Entity Framework takes care of tracking the state of entities while they are connected to a context, but in disconnected or N-Tier scenarios you can let EF know what state your entities should be in. The techniques shown in this topic apply equally to models created with Code First and the EF Designer.

Event publish and subscribe example

http://msdn.microsoft.com/en-us/library/w369ty8x.aspx

Example of event publish and subscribe

 Read more of this post

EventHandler

http://msdn.microsoft.com/en-us/library/ms366768.aspx

// C# non-generic version
[SerializableAttribute]
[ComVisibleAttribute(true)]
public delegate void EventHandler(Object sender,EventArgs e)

// C# 2.0:  Generic version
[SerializableAttribute]
public delegate void EventHandler<TEventArgs>(Object sender, TEventArgs e)

Read more of this post

The evolution of delegate creation from C# 1.0 to C# 3.0

http://msdn.microsoft.com/en-us/library/bb882516.aspx

http://msdn.microsoft.com/en-us/library/ms173176.aspx

In C# 1.0, you created an instance of a delegate by explicitly initializing it with a method that was defined elsewhere in the code. C# 2.0 introduced the concept of anonymous methods as a way to write unnamed inline statement blocks that can be executed in a delegate invocation. C# 3.0 introduced lambda expressions, which are similar in concept to anonymous methods but more expressive and concise.

Read more of this post

IEnumerable vs. IQueryable

http://www.codeproject.com/Articles/732425/IEnumerable-Vs-IQueryable

Below lists the differences between them based on their properties :

Read more of this post

Object copy

http://en.wikipedia.org/wiki/Object_copy#Shallow_copy

Shallow copy

One method of copying an object is the shallow copy. In the process of shallow copying A, B will copy all of A’s field values. If the field value is a memory address it copies the memory address, and if the field value is a primitive type it copies the value of the primitive type.

Deep copy

An alternative is a deep copy. Here the data is actually copied over. The result is different from the result a shallow copy gives. The advantage is that A and B do not depend on each other but at the cost of a slower and more expensive copy.

Read more of this post