if anyone using abstarction and interfaces in your applications can u share that code.....just want to know when we go for abstraction and interfaces in .net applications

For abstract classes try to think of the most common members of multiple classes that are all similar. An example of this is DbConnections:

Oracle, SQL, OleDb, and ODBC connections...

public sealed class SqlConnection : DbConnection, ICloneable
public sealed class OleDbConnection : DbConnection, ICloneable, IDbConnection, IDisposable
public sealed class OdbcConnection : DbConnection, ICloneable
public sealed class OracleConnection : DbConnection, ICloneable

All descend from the abstract base...

public abstract class DbConnection : Component, IDbConnection, IDisposable

Connection specific properties such as DSN can be added as members to the ODBC class since it only applies to that individual connection (but in this case the DSN is the connection string). Now that we have abstracted the major connection types to a common class, we can use DbCommand.Execute() to handle any type of DB connection from the same code.

The difference in descending versus an abstract class is that you can not instantiate an abstract class, a class must be derived from it in order for it to be usable. A database connection by itself is a concept, an abstract concept. A connection to MSSQL-Server is an implementation of the concept which can be instantiated.

I have a database connection wrapper class I use for my data access, here is an example:

private DbConnection GetDbConnection()
    {
      DbConnection result = null;

      switch (_connectionType)
      {
        case ConnectionWrapperType.ODBC:
          result = new OdbcConnection(_connectionString);
          break;
        case ConnectionWrapperType.OleDb:
          result = new OleDbConnection(_connectionString);
          break;
        case ConnectionWrapperType.Oracle:
          result = new OracleConnection(_connectionString);
          break;
        case ConnectionWrapperType.SQL:
          result = new SqlConnection(_connectionString);
          break;
        default:
          throw new InvalidEnumArgumentException("Invalid enumeration member", (int)_connectionType, _connectionType.GetType());
      }
      return result;
    }
    public int Execute(string query, List<DataParameter> parms)
    {
      int result = 0;
      using (DbConnection conn = GetDbConnection())
      {
        conn.Open();
        using (DbCommand cmd = GetDbCommand(query, parms, conn))
        {
          LogQuery(query, parms);
          result = cmd.ExecuteNonQuery();
        }
        conn.Close();
      }
      return result;
    }

Please be careful to use words - abstraction and abstract. Abstraction is an integrated element of Object-Oriented Program Design.

All programming languages provide abstractions. It can be argued that the complexity of the problems you're able to solve is directly related to the kind and quality of abstraction.

Assembly language is a small abstraction of the underlying machine. Many so-called "imperative" languages that followed (C, C++, Java etc) were abstraction of assembly language.

With an abstraction we cleanly separate the programming tasks of implementation and usage: we are well on our way to decompose a large system into smaller modules.

Abstract data types (ADT) satisfy the good programing principles of information hiding and divide and conquer.

An abstract Class is one that is not used to create an object. An abstract class is designed only to act as a base class.

The abstract modifier declares an abstract class. The abstract class is an incomplete class that can act only as a base class; it cannot be instantiated.

This article has been dead for over six months. Start a new discussion instead.