Define Inteface , Implement a class , method , clearly with simple examples , Instance class

Showing Answers 1 - 3 of 3 Answers

kashinathn

  • Feb 27th, 2007
 

Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.

<%@ Page Language="C#" %>
<script runat="server">

 //private variables
 private IDataSource m_DataSource = null;

public void Page_Load(Object sender, EventArgs E) {

  //main
  m_DataSource = new AccessDataSource();
  Response.Write("Connection string = " + m_DataSource.ConnectionString + "<br/>");
  Response.Write("Test result = " + m_DataSource.Test() + "<br/>");

}

public interface IDataSource {
 string ConnectionString { get; }
 string Test();
}

public class AccessDataSource : IDataSource {

  //constants
  public const string CONNECTION_STRING = "Server=....;bla...bla...bla...";

  public string ConnectionString {
   get { return CONNECTION_STRING; }
  }

  public string Test() {
   return "this is a test";
  }

}

</script>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions