抽象类中内部抽象方法的目的是什么? [英] What is the purpose of internal abstract method in a abstract class?

查看:89
本文介绍了抽象类中内部抽象方法的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抽象类中内部抽象方法的目的是什么?

为什么要在抽象类中内部创建抽象方法?如果我们想限制程序集之外的抽象类,为什么我们不只是创建抽象的内部类。

它背后是否有任何其他逻辑。

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.

推荐答案

当你想要创建一个抽象但希望它与你的代码内部或第三方用户的代码不同时,它会很有用......

喜欢启用覆盖您自己的代码中的特定方法,但不适用于您的库的用户...

我有一个示例是Telerik的控件,其中呈现客户端JavaScript的方法被定义为内部......所以在Telerik的控件之间它被覆盖了,但是我作为最终用户被隐藏了......(我相信原因不是让你弄乱他们的控件)
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)


如果你真的在谈论内部抽象方法,它并没有告诉我们关于类的访问修饰符的任何信息,所以它可以是内部的或公共的,内部类也可以是私有的,这是相当于内部,但限制范围到该类的声明类。



如果课程本身也是内部的,我希望你不会看到任何争议。让我们假设您在本课程公开时看到了争议。但这种争议纯属可想而知,也许是因为你假设太多了。如果你认为某些抽象方法必须在程序集之外的某些代码中重写,你会假设太多,缺少明显的逻辑。谁会告诉你的?当然,抽象方法只有在最终被覆盖时才有意义,但为什么它或所有被覆盖的版本都应该在程序集外部可访问。所有这些方法的整个集合可能只是实现细节的一部分,不能由此公共类的用户直接访问。事实上,神秘不仅仅是微不足道的。 (当然,如果你审查的代码是合理的。)



-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


这篇关于抽象类中内部抽象方法的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆