Why is this variable declared as private and also readonly?

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-06-13T19:20:11Z Indexed on 2010/06/13 19:32 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

In the following code:

public class MovieRepository : IMovieRepository
{
    private readonly IHtmlDownloader _downloader;

    public MovieRepository(IHtmlDownloader downloader)
    {
        _downloader = downloader;
    }

    public Movie FindMovieById(string id)
    {
        var idUri = ...build URI...;

        var html = _downloader.DownloadHtml(idUri);

        return ...parse ID HTML...;
    }

    public Movie FindMovieByTitle(string title)
    {
        var titleUri = ...build URI...;

        var html = _downloader.DownloadHtml(titleUri);

        return ...parse title HTML...;
    }
}

I asked for something to review my code, and someone suggested this approach. My question is why is the IHtmlDownloader variable readonly?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET