Adalat  Khan

Adalat Khan

  • 647
  • 1.5k
  • 870k

Interface and its Implementation

Aug 31 2021 7:09 AM

Hi,

I have a question.

Why we declare an object from a class or interface as property object? whats the logic behind this. Why we not declare an object instead of property?. Following is the example:

public interface ICacheManager
{
    T GetData(CacheDataType type, string location = null, string client = null, string customKey = null);
    Task GetDataAsync(CacheDataType type, string location = null, string client = null, string customKey = null);
    List GetList(CacheDataType type, string location = null, string client = null, string customKey = null);
    Task GetListAsync(CacheDataType type, string location = null, string client = null, string customKey = null);
    void ReloadData(string location = null, string client = null);
    void ReloadData(CacheDataType type, string location = null, string client = null);
    void StoreData(CacheDataType type, T data, TimeSpan? slidingExpiry = null, string location = null, string client = null, string customKey = null);
}

//Implementation class
public class LocationService : ILocationService
{
    ICacheManager _cacheManager { get; set; }
    public LocationService(IConfigManager configManager)
    {
        _cacheManager = cacheManager;
    }
}

In the above class LocationService we declared a property object from the interface ICacheManager. Why we not declare an object instead of property? Whats the purpose behind this?


Answers (4)