Click here to Skip to main content
16,018,805 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is the purpose of internal abstract method in a abstract class?
why to make an abstract method internal in a abstract class? if we want to restrict abstract class outside the assembly why don't we just make abstract internal class.
Is there any other logic behind it.
Posted

It can be useful when you want to create a single abstract but want it to be different from inside your code or from code of a 3rd party user...
Like enabling the overriding of a specific method from your own code, but do not for a user of your library...
One sample I had is with Telerik's controls, where the method to render the client side JavaScript was defined as internal...So between controls of Telerik it was overrided, but me, as an end-user it was hidden...(I believe the reason is not let you mess their controls)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Feb-15 9:48am    
What 3rd-party user? From the same assembly? No, it can be only for internal purpose. Can make full sense though. I'll answer...
—SA
Kornfeld Eliyahu Peter 23-Feb-15 9:50am    
3rd-party user - I meant someone (a developer) from the outside who uses your classes/library...
Sergey Alexandrovich Kryukov 23-Feb-15 9:57am    
That's the point. Such user cannot override this method, as it is marked internal. Please see my answer; I explained why there is no a controversy.
—SA
Kornfeld Eliyahu Peter 23-Feb-15 10:03am    
I didn't try to tell that there is any controversy...I tried to show a sample of how it can be useful...
Sergey Alexandrovich Kryukov 23-Feb-15 10:16am    
No, you did not understand me. It's the nature of the inquirer's question, not your post. The inquirer sees some not really existing controversy. Perhaps you answer is just unclear...
—SA
If you are really talking about internal abstract method, it does not tell us anything about the class's access modifier, so it can be either internal or public, and the inner class can also be private, which is equivalent to internal, but limiting the scope to that class's declaring class.

If the class itself is also internal, I hope you won't see any controversies. Let's assume that you see the controversies when this class is public. But such controversies are purely imaginable, perhaps because you assume too much. If you thought that some abstract method has to overridden in some code outside of the assembly, you would assume too much, missing apparent logic. Who would tell you so? Of course, an abstract method only makes sense when it is eventually overridden, but why it or all overridden versions should be accessible outside the assembly. The whole set of all those methods could be just a part of implementation detail, not directly accessible by the users of this public class. The "mystery" is in fact more than trivial. (Of course if the code you review is reasonable.)

—SA
 
Share this answer
 
Comments
mahakaal 23-Feb-15 23:18pm    
i am not clear about it yet.
if making an abstract class internal can restrict it's access from outside the assembly than what is the purpose of making it's abstract method internal.

what are benefits in both context...
Sergey Alexandrovich Kryukov 23-Feb-15 23:42pm    
Which part of my answer was not clear to you?
Are you sure you really understand these access specifiers? It's not that "internal can restrict". More exactly, "internal" makes the top-level type or the member of this type accessible from any code of the assembly. Public extents this access to other assemblies, let's forget them for now. Your question was about internal abstract method, not internal class. The class could have any other access modifier (but of course private could be only for the nested class). Is that clear?

What you are asking should be derived from that plus understanding the purpose of abstract methods. Combine these two. Ask yourself: do you understand access specifiers I explained above? Then ask yourself: do you understand the purpose of abstract methods in general, regardless of access? If you do, combine these facts together. If you still don't see the possible purpose of internal abstract method, try to explain why not, ask your question in more detailed way. What exactly is not clear.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900