Reputation: 128
Can you guys explain me how can I get object properties when I have arguments who are interface type?
public interface IObject {}
public class Object : IObject {}
And then I have some methods like this :
public void Add(IObject object)
{
object.someThing; // I want to get that property but I can't.
}
What type should I use to get these properties? What's best practice?
Upvotes: 1
Views: 98
Reputation: 135
An Interface is a contract to be implemented by a class, which means
whatever rules ( methods and properties ) that the interface contains will need to be implemented by the classes that implement the interface
So, when you accept a method with an interface as the type in the parameter, you are stating that the object that will be passed to the method will contain methods and properties as stated by the interface.
Hence, the methods that you wish to invoke on the object should be defined in the interface.
Upvotes: 2