私はIoCを習得し、実際に実践しようとしています。これは私にとって非常に難しいです。ここに私がこれまで持っていたコードがあります。私が作った間違いはありますか?それらを私に指摘すれば、それが実践されたときに実際にどのように適合するかを理解するのに役立ちます。このコードはデカップリングされていますか?
ありがとうございます!
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);
}
}
}
このコードで何を変更しますか?私はこの権利をしていますか?
編集: DownloadInformation()メソッドは実際に何もしていないことに注意してください。私の意図は、インターフェイスをそのメソッドを持たせることでした。その方法で、XMLから情報を取得できますが、JSONに切り替えることも、プロバイダが今後提供する可能性のあるものにすることもできます。
あなたのコードにはIoCがありません。 – VVS
ありがとう、あなたのコメントは私を大いに助けます。 /秒 –