Estoy tratando de aprender y poner en práctica IoC y cómo programar contra interfaces en lugar de objetos. Esto es bastante difícil para mí. Aquí está el código que tengo hasta ahora. ¿Hay algún error que haya cometido? Señalarlos me ayudará a entender cómo encaja realmente cuando se ponga en práctica.¿Este código está desacoplado y lo estoy haciendo bien?
Gracias!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpDIC.Api.Interfaces
{
interface IDownloader
{
void DownloadInformation();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDIC.Api.Interfaces;
namespace SharpDIC.Api.Models
{
public class Member
{
/********************************************************************************
* Some of these attributes aren't even used. The API doesn't provide them yet, *
* so I'll have to scrape the information from the HTML itself. Still thinking *
* about how to tackle this. *
* *
* Author: Sergio Tapia *
* Website: http://www.alphaot.com
* Date: 16/12/2010
* ******************************************************************************/
#region "Attributes"
public string ID { get; set; }
public string Name { get; set; }
public string Rating { get; set; }
public string Photo { get; set; }
public string LastActive { get; set; }
public string Location { get; set; }
public string Birthday { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
public string Email { get; set; }
public string Title { get; set; }
public string Reputation { get; set; }
public string DreamKudos { get; set; }
public string Group { get; set; }
public string Posts { get; set; }
public string PostsPerDay { get; set; }
public string MostActiveIn { get; set; }
public string JoinDate { get; set; }
public string ProfileViews { get; set; }
public string FavoriteOs { get; set; }
public string FavoriteBrowser { get; set; }
public string FavoriteProcessor { get; set; }
public string FavoriteConsole { get; set; }
public List<Visitor> Visitors { get; set; }
public List<Friend> Friends { get; set; }
public List<Comment> Comments { get; set; }
public string ProgrammingLanguages { get; set; }
public string Aim { get; set; }
public string Msn { get; set; }
public string Website { get; set; }
public string Icq { get; set; }
public string Yahoo { get; set; }
public string Jabber { get; set; }
public string Skype { get; set; }
public string LinkedIn { get; set; }
public string Facebook { get; set; }
public string Twitter { get; set; }
public string XFire { get; set; }
#endregion
}
public class Comment
{
public string ID { get; set; }
public string Text { get; set; }
public string Date { get; set; }
public string Owner { get; set; }
}
public class Friend
{
public string ID { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Photo { get; set; }
}
public class Visitor
{
public string ID { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Photo { get; set; }
public string TimeOfLastVisit { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using SharpDIC.Api.Interfaces;
using SharpDIC.Api.Models;
namespace SharpDIC.Api
{
public class Wrapper : IDownloader
{
public void DownloadInformation()
{
}
public Member SearchForMember(int memberID)
{
XDocument response = GetXmlResponse(memberID);
//Member then is responsible to parse and fill his contents.
Member member = new Member(response);
}
}
}
¿Qué cambiarías en este código? ¿Lo estoy haciendo bien?
Editar: Observe que el método DownloadInformation() en realidad no está haciendo nada. Mi intención era tener una interfaz con ese método, de esa manera puedo obtener la información del xml (por ahora) pero también puedo cambiar a JSON o lo que el proveedor pueda ofrecer en el futuro.
no veo COI en su código. – VVS
Gracias, tu comentario me ayuda tremendamente./s –