Interfaces and Abstractions
Interface Intro
An interface names behavior that a class promises to provide.
Interface Intro
InterfaceIntro.cs
using System;
interface ILabel
{
string Label();
}
class NameTag : ILabel
{
private readonly string name;
public NameTag(string name)
{
this.name = name;
}
public string Label()
{
return "tag:" + name;
}
}
class Program
{
static void Main()
{
string name = ;
NameTag tag = new NameTag(name);
string label = tag.Label();
Console.WriteLine($"name={name}");
Console.WriteLine($"label={label}");
}
}
using System;
interface ILabel
{
string Label();
}
class NameTag : ILabel
{
private readonly string name;
public NameTag(string name)
{
this.name = name;
}
public string Label()
{
return "tag:" + name;
}
}
class Program
{
static void Main()
{
string name = ;
NameTag tag = new NameTag(name);
string label = tag.Label();
Console.WriteLine($"name={name}");
Console.WriteLine($"label={label}");
}
}
using System;
interface ILabel
{
string Label();
}
class NameTag : ILabel
{
private readonly string name;
public NameTag(string name)
{
this.name = name;
}
public string Label()
{
return "tag:" + name;
}
}
class Program
{
static void Main()
{
string name = ;
NameTag tag = new NameTag(name);
string label = tag.Label();
Console.WriteLine($"name={name}");
Console.WriteLine($"label={label}");
}
}
interface
An interface describes methods or properties without storing object state.