public interface ISetting { } public class ApplicationSetting:ISetting { string Setting1 {get;set;} string Setting2 {get;set;} } public class AnotherSetting : ISetting { string AnotherSetting1{get;set;} string AnotherSetting2{get;set;} }
I guess this is called a marker interface, isn’t it? I asked because I only know how to use interface with members or properties inside of them. So for example, I do have this code.
public interface IData { List<string> Data { get;} }
I could derive a class from this and use a pattern like strategy but I really don’t have an idea how to use an interface without members.
I also did some research about marker interfaces and I saw this code.
public interface IContainSensitiveInformation { } public class Customer : IContainSensitiveInformation { public string LastName { get; set; } public string SocialSecurityName { get; set; } public string CreditCardNumber { get; set; } } public void SaveCustomer(Customer customer) { if (customer is IContainSensitiveInformation) _secureService.SaveCustomer(customer); else _regularService.SaveCustomer(customer); }
Source : Marker Interface
Yes, I can understand the code sample above but I really don’t have an idea when to use it on a real-world project. Looking at the example above, why would you check if a class implemented IContainSensitiveInformation?. Would love to have someone explain things up for me to better understand when to use a marker interface.
Regards