一个类的可访问性 [英] Accessibility of a Class

查看:107
本文介绍了一个类的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想设计一个解决方案,但由于对OOP概念的了解有限而面临问题。我的要求如下



假设我有4节课

A级

B级

C级

D级



我想要D类的对象只能被允许创建,或者类只能是可以在C类中访问。可以允许在B类中访问和创建相同的C类对象和类本身.D类不应该访问B类。

相同的A类不应该访问C, D.它只能访问B,它可以创建B的对象。



我们如何在C#中实现最佳架构。



最好的问候。

Hello, I want to design a solution, but facing a problem because of limited knowledge of OOPs concept. My requirement is as follows

Assume I have 4 classes
Class A
Class B
Class C
Class D

I want object of class D can only be allowed to create, or class can only be accessible in Class C. Same Class C object and class itself can be allowed access and created in Class B. Class D should not have access to class B.
Same Class A should not have access to C, D. It only have access to B, and it can create object of B.

How we can implement with best possible architecture in C#.

With Best Regards.

推荐答案

C#和.NET不允许这种访问限制。访问规则更简单,并在MSDN中有详细描述:

http:/ /msdn.microsoft.com/en-us/library/ms173121.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/vstudio/wxh6fsc7.aspx [ ^ ]。



-SA
C# and .NET does not allow access constraints of this kind. The access rules are much simpler and are well described in MSDN:
http://msdn.microsoft.com/en-us/library/ms173121.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/wxh6fsc7.aspx[^].

—SA


阅读



C#中的多重继承 [ ^ ]



继承介绍,C#中的多态性 [ ^ ]



继承 [ ^ ]
Read

Multiple Inheritance in C#[^]

Introduction to inheritance, polymorphism in C#[^]

Inheritance[^]


或使用不同的命名空间,您可以处理您的问题
or by using different namespaces you can deal with your problem


这篇关于一个类的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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