Hello everyone,
I understand in the rule of C#, we are not allowed to add public/private/protected qualifier to methods in interface. My question is why adding the qualifiers are not allowed? I want to know the reason behind the claimed rule, i.e. what issues will be if we are allowed to add qualifier?
thanks in advance,
George
Bechir BejaouiRank #144 · 15.9K pointsPosted Oct 27, 2008, 2:34 AM EDT
if they are marked as private so they could'nt be viewed ouside the interface scoop on one hand
in the other hand, if they are marked as protected will do not make sens as the interface contains only methods contracts and not implementations going to be modified
George GeorgeRank #2,261 · 618 pointsPosted Oct 27, 2008, 3:40 AM EDT
Thanks.
1.
I can understand that you mean if interface method is marked as private, then the implementation must be private and the implementation could not be accessed from outside? Is that your point?
2.
My confusion is what do you mean "if they are marked as protected will do not make sens as the interface contains only methods contracts and not implementations going to be modified"? Could you show some pseudo code to describe your ideas please?
regards,
George
Bechir BejaouiRank #144 · 15.9K pointsPosted Oct 30, 2008, 3:27 AM EDT
2. For the second question, I thing if you have to use protected keyword then abstract class is the best solution. To be more clear, the interface concept is used only for contracts context and not for implementation context
George GeorgeRank #2,261 · 618 pointsPosted Oct 30, 2008, 5:16 AM EDT
Can you show me how to make a method of an interface private please? I am confused and I tried seems we can not.
regards,
George
Bechir BejaouiRank #144 · 15.9K pointsPosted Oct 31, 2008, 4:07 PM EDT
private: only visible inside a unique class
protected: only visible inside the class and the derived types
public: visible by different types