Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created December 20, 2010 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanplopes/748812 to your computer and use it in GitHub Desktop.
Save juanplopes/748812 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var di = new Container();
di.Registrar<IFerramentaParaEscrever, Caneta>();
di.Registrar<ICoisaQueAceitaEscrita, Papel>();
var pessoa = di.Resolve<Pessoa>();
pessoa.EscreverDiario();
}
}
public class Pessoa
{
private ICoisaQueAceitaEscrita _coisa;
private IFerramentaParaEscrever _ferramenta;
public Pessoa(ICoisaQueAceitaEscrita coisa, IFerramentaParaEscrever ferramenta)
{
_coisa = coisa;
_ferramenta = ferramenta;
}
public void EscreverDiario()
{
_ferramenta.Escrever(_coisa, "bla bla bla");
}
}
public interface ICoisaQueAceitaEscrita
{
string Texto { get; set; }
}
public interface IFerramentaParaEscrever
{
void Escrever(ICoisaQueAceitaEscrita coisa, string texto);
}
public class QuadroNegro : ICoisaQueAceitaEscrita
{
#region ICoisaQueAceitaEscrita Members
public string Texto
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
}
public class Giz : IFerramentaParaEscrever
{
#region IFerramentaParaEscrever Members
public void Escrever(ICoisaQueAceitaEscrita coisa, string texto)
{
throw new NotImplementedException();
}
#endregion
}
public class Papel : ICoisaQueAceitaEscrita
{
public string Texto { get; set; }
}
public class Caneta : IFerramentaParaEscrever
{
public void Escrever(ICoisaQueAceitaEscrita papel, string texto)
{
papel.Texto += texto;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment