Translate

Monday, October 31, 2011

Principles of software design


Every software application, whether you apply design patterns or not, you should adhere to the design principles. Applying design principles makes your application robust and easy to maintain. Also design principles must be learned before you can embark on a journey to learn design patterns.  Allow me to introduce you to design principles with the so called SOLID design principles.

S:   Single Responsibility Principle
Like the name suggests, what this means is that every object should be built for one reason only. You should avoid writing multi purpose classes. For example in the .net class library, the string functions are in its own single purpose System.String class and the math functions are in System.Math class. 

O:  Open-Closed Principle
A class should be open for extension and closed for modification. This means once a class has had a stable release, the existing functionality should never be modified. It it however okay to add new functionality.

L:   Liskov Substitution Principle
This principle states that you should be able to use a derived class in place on the parent class and  the derived class should behave the same as its parent class.

I:    Interface Segregation Principle
This principle is tells you to separate interfaces based on their responsibility. Do not have one huge interface for everything. For example imagine the IEnumerable interface also made you implement a lot of methods that you don't need for a foreach loop. Thats obviously an unwanted inconvenience, if all you want is to apply a foreach loop. This is avoided by having only the methods required for a foreach loop as a part of the IEnumerable interface.

D:   Dependency Inversion Principle (or the Inversion of Control Principle )
The Dependency Inversion Principle states when one class uses another class, both the code in both classes can be totally independent of each other and should only depend on interfaces (or abstract classes).
There are three ways to achieve this, namely
  • Constructor Injection
  • Method Injection
  • Property Injection



The  Dependency Inversion Principle is a concept that will take a little more reading to understand. I would strongly recommend checking out these two articles, which explains this concept in a lot more detail.
http://dotnetanalysis.blogspot.com/2012/05/programming-to-interface-in-c.html
http://dotnetanalysis.blogspot.com/2011/11/dependency-inversion-or-inversion-of.html




Sunday, October 30, 2011

C# ?? operator (null coalescing operator)

int? a=null; //int? means a nullabe int. In other words an int variable that can be set to null
int? b;

b = 5;
int? c = a ?? b;//This means pick a if it is not null, else pick b

Console.WriteLine(c);//Displays 5

Saturday, October 22, 2011

Asp.net mvc releases


Release Name
Release Date
Download available at



Asp.net MVC 1
March 2009
Asp.net MVC 2
March 2010
Asp.net MVC 3
Jan 2011





Monday, October 17, 2011

SQL Server : Find all stored procedures

Find all stored procedures in a database:
select * from sys.objects where type_desc='SQL_STORED_PROCEDURE'


Find all the scalar functions in a database:
select * from sys.objects where type_desc='SQL_SCALAR_FUNCTION'


Find all tables in a database:
select * from sys.objects where type_desc='USER_TABLE'

Find all columns in a database:
select * from sys.columns

Find all triggers in a database:
select * from sys.objects where type_desc='SQL_TRIGGER'

Find all the views in a database
select * from sys.objects where type_desc='VIEW'