Quantcast
Channel: Program to an interface not an implementation confusion - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Program to an interface not an implementation confusion

$
0
0

I'm trying to get into the habit of coding to an interface rather than an implementation and whilst in most cases I can see the reasoning there are a few where I struggle.

Take this really simple example:

public interface IAuditLog{    void AddLog(string log);}public class AuditLog : IAuditLog{    public void AddLog(string log)    {        //implementation    }}

To call the audit log class:

public partial class AuditLogPage : System.Web.UI.Page{    protected void btnAddLog_Click(object sender, EventArgs e)    {        IAuditLog objAuditLog = new AuditLog();        objAuditLog.AddLog("test log");    }}

I still have to use AuditLog when instantiating, so what's the point? If the AddLog method signature changes i'm still going to have to go through all my pages that use it and amend the code. Am I missing the point?

Thanks for any help in advance,Wilky.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images