CSharp类设计问题 [英] CSharp Class Design Issue

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

问题描述

大家好,

我对课程范围和

可见性有严重问题。在我的申请中,我有一个类

名称TextFile,还有一些其他类

,如TotalWords,TotalLines等。等等..,
假设描述我的主TextFile

类的结构。此外,我已经创建了一些自定义集合类,

只接受类型的项目,它们是专为。

现在的问题是我想要我的元素类,

类似于TotalWords,TotalLines等。只能看到我的主要文件TextFile的

子项。类,即一次我创建一个TextFile的实例。这类

其他类是否可见,以创建TextFile的详细信息。

在我的代码中应该放置这些类的地方以及

他们的收藏品(包装类)。

我面临的主要问题是,我的收藏品是多次增加,而且我在一个大的残骸中


预先感谢您的任何考虑

问候! Sunny

解决方案

Sunny,


你不能说整个班级只对特定的人可见

级。如果有的话,你可以做的最好的事情是将你的其他类声明为

internal,并确保它们与

TextFile类在同一个地方定义。这样,只有程序集中的类可以看到该类

(包括你的TextFile类)。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv *@spam.guard.caspershouse.com

Sunny < GH ********** @ yahoo.com>在留言中写道

news:0c **************************** @ phx.gbl ... < blockquote class =post_quotes>大家好,
我对课程范围和可见性有严重的问题。在我的应用程序中,我有一个类名称TextFile,还有一些其他类
如TotalWords,TotalLines等。等等..,它们是用来描述我的主要TextFile类的结构。此外,我已经创建了一些自定义集合类,
只接受类型的项目,它们是专为。
现在的问题是我想要我的元素类,
像TotalWords ,TotalLines,仅对我主要的孩子们可见,TextFile类,一旦我创建了一个TextFile的实例。 class应该可以看到其他类,以创建TextFile的细节。
在我的代码中我应该放置这些类以及它们的集合(包装类)。
我面临的主要问题是,我的收藏品多次递增,我在一个大的残骸中

提前感谢您的任何考虑
关心! Sunny



看,这并不能解决我的问题,单独,也是

这个概念也没有意义,请参阅,没有

有这样的点


TextFile.Comment()(没有意义,因为你会这样的。
需要这个)


TextFile aFile = new TextFile(Name,loc,..)(看起来不错)

现在,这个有意义

aFile.Comment()= new Comment()....(因为在这里你会

需要它们)


但是如何要做到这一点,那就是make Comments()类

仅对TextFile()的孩子可见.....

问题仍然存在...... ..


有问候

Sunny

-----原始消息----- <晴朗,

你不能说整个班级只有
a特级才能看到。如果有的话,你可以做的最好的事情就是将你的
其他类声明为内部,并确保它们与theTextFile类在同一个
中定义。这样,只有程序集
中的类才能看到该类(包括你的TextFile类)。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
Sunny < GH ********** @ yahoo.com>在消息中写道
新闻:0c **************************** @ phx.gbl ...

大家好,
我对课程范围和可见性有严重的问题。在我的应用程序中,我有一个类名称TextFile,还有一些其他类
如TotalWords,TotalLines等。等等..,它们是用来描述我的主要TextFile类的结构。此外,我已经创建了一些自定义集合
类,它们只采用类型的项目,它们被设计为
。现在的问题是我想要我的元素类,例如TotalWords,TotalLines等。只有
可见我的主要孩子,TextFile和类,一旦我创建了一个TextFile的实例。 class应该可以看到其他类,以创建
TextFile的详细信息。在我的代码中我应该放置这些类,还有它们的集合(包装类)。
我面临的主要问题是,我的收藏品多次递增,我是在一个巨大的
残骸中
在此先感谢您的任何考虑
关心! Sunny





Sunny,


我''我不太确定你要做什么。以下不是

正确的语法:


aFile.Comment()= new评论()


你无法将一个对象分配给一个方法(这就是注释末尾的括号

)。


你不能只让一个类可见去另一个班级。您可以使用的最低

级别是使用内部关键字在同一

程序集中的其他类可访问该类。


现在,如果你不希望将Comment属性/方法暴露给

除了TextFile类的子项之外的任何人,那么你可以设置

的可访问性保护,只有自己和派生成员将能够访问它。


希望这会有所帮助。

- -

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com


" Sunny" < GH ********** @ yahoo.com>在留言中写道

news:05 **************************** @ phx.gbl ... < blockquote class =post_quotes>看,这并不能解决我的问题,单独,也是
这个概念也没有意义,看,没有这样的意思

TextFile.Comment()(没有意义,因为你会需要这个)

TextFile aFile = new TextFile(Name,loc,..)(看起来不错)
现在,这个有意义
aFile.Comment()=新评论()....(因为在这里你会需要它们)

但是如何做到这一点,就是使得Comment()类
只对TextFile()的孩子可见.....
问题仍然存在.....
<关于
Sunny

-----原帖-----
Sunny,

你可以不要说整个班级仅对


特定的

类可见。如果有的话,你能做的最好就是将


其他类声明为

internal,并确保它们在同一个


位置定义作为

TextFile类。这样,只有程序集中的类


才能看到类

(包括你的TextFile类)。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv * @ spam。 guard.caspershouse.com

Sunny < GH ********** @ yahoo.com>在消息中写道
新闻:0c **************************** @ phx.gbl ...

大家好,
我对课程范围和可见性有严重的问题。在我的应用程序中,我有一个类名称TextFile,还有一些其他类
如TotalWords,TotalLines等。等等..,它们是用来描述我的主要TextFile类的结构。此外,我已经创建了一些自定义集合类,它们只采用了它们的类型项目。现在的问题是我想要我的元素类,例如TotalWords,TotalLines等。仅对我的主要孩子TextFile可见。类,一旦我创建了一个TextFile的实例。 class应该可以看到其他类,以创建TextFile的细节。在我的代码中我应该放置这些类,还有它们的集合(包装类)。
我面临的主要问题是,我的收藏品多次递增,我是在一个大的残骸中
感谢提前做任何考虑
关心! Sunny





Hi All,
I have a serious issue regarding classes scope and
visibility. In my application, i have a class
name "TextFile", and also a few other classes
like "TotalWords", "TotalLines" and etc.., which are
suppose to describe the structure of my main TextFile
class. Also i have created some custom collection classes,
which only take items of the types, they are designed for.
Now the problem is that I want my element classes,
like "TotalWords", "TotalLines" to be visible only to the
children of my main, "TextFile" class, that is once i
create an instance of a "TextFile" class should these
other classes be visible, to create details of a TextFile.
Where in my code should i place these classes and also
their collection (wrapper classes).
The main problem i am facing is that, my Collections are
getting incremented multiple times, and i am in a big wreck

Thanks in Advance for any consideration
With Regards! Sunny

解决方案

Sunny,

You can not say that a whole class is only visible to a particular
class. If anything, the best you can do is declare your other classes as
internal and make sure that they are defined in the same place as the
TextFile class. This way, only classes in the assembly can see that class
(including your TextFile class).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sunny" <gh**********@yahoo.com> wrote in message
news:0c****************************@phx.gbl...

Hi All,
I have a serious issue regarding classes scope and
visibility. In my application, i have a class
name "TextFile", and also a few other classes
like "TotalWords", "TotalLines" and etc.., which are
suppose to describe the structure of my main TextFile
class. Also i have created some custom collection classes,
which only take items of the types, they are designed for.
Now the problem is that I want my element classes,
like "TotalWords", "TotalLines" to be visible only to the
children of my main, "TextFile" class, that is once i
create an instance of a "TextFile" class should these
other classes be visible, to create details of a TextFile.
Where in my code should i place these classes and also
their collection (wrapper classes).
The main problem i am facing is that, my Collections are
getting incremented multiple times, and i am in a big wreck

Thanks in Advance for any consideration
With Regards! Sunny



See, this does not solves my prob, alone, also
The concept does not makes sense either, see, there is no
point of having like this

TextFile.Comment() (Does not makes sense, as y one would
need this)

TextFile aFile = new TextFile(Name, loc, ..) (Looks good)
Now, this one would make sense
aFile.Comment() = new Comment().... (since here u would
need them)

But how to do it like this, that is make Comments() class
visible only to children of TextFile().....
The problem is still there .....

With Regards
Sunny

-----Original Message-----
Sunny,

You can not say that a whole class is only visible to a particularclass. If anything, the best you can do is declare your other classes asinternal and make sure that they are defined in the same place as theTextFile class. This way, only classes in the assembly can see that class(including your TextFile class).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sunny" <gh**********@yahoo.com> wrote in message
news:0c****************************@phx.gbl...

Hi All,
I have a serious issue regarding classes scope and
visibility. In my application, i have a class
name "TextFile", and also a few other classes
like "TotalWords", "TotalLines" and etc.., which are
suppose to describe the structure of my main TextFile
class. Also i have created some custom collection classes, which only take items of the types, they are designed for. Now the problem is that I want my element classes,
like "TotalWords", "TotalLines" to be visible only to the children of my main, "TextFile" class, that is once i
create an instance of a "TextFile" class should these
other classes be visible, to create details of a TextFile. Where in my code should i place these classes and also
their collection (wrapper classes).
The main problem i am facing is that, my Collections are
getting incremented multiple times, and i am in a big wreck
Thanks in Advance for any consideration
With Regards! Sunny


.



Sunny,

I''m not quite sure what you are trying to do. The following is not
correct syntax:

aFile.Comment() = new Comment()

You can not assign an object to a method (that is what the parenthesis
at the end of Comment mean).

You can not make a class visible only to another class. The lowest
level you can go is make the class accessible to other classes in the same
assembly, using the internal keyword.

Now if you don''t want the Comment property/method to be exposed to
anyone but children of the TextFile class, then you can set the
accessibility of that to protected, and only itself and derived members will
be able to access it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sunny" <gh**********@yahoo.com> wrote in message
news:05****************************@phx.gbl...

See, this does not solves my prob, alone, also
The concept does not makes sense either, see, there is no
point of having like this

TextFile.Comment() (Does not makes sense, as y one would
need this)

TextFile aFile = new TextFile(Name, loc, ..) (Looks good)
Now, this one would make sense
aFile.Comment() = new Comment().... (since here u would
need them)

But how to do it like this, that is make Comments() class
visible only to children of TextFile().....
The problem is still there .....

With Regards
Sunny

-----Original Message-----
Sunny,

You can not say that a whole class is only visible to


a particular

class. If anything, the best you can do is declare your


other classes as

internal and make sure that they are defined in the same


place as the

TextFile class. This way, only classes in the assembly


can see that class

(including your TextFile class).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sunny" <gh**********@yahoo.com> wrote in message
news:0c****************************@phx.gbl...

Hi All,
I have a serious issue regarding classes scope and
visibility. In my application, i have a class
name "TextFile", and also a few other classes
like "TotalWords", "TotalLines" and etc.., which are
suppose to describe the structure of my main TextFile
class. Also i have created some custom collection classes, which only take items of the types, they are designed for. Now the problem is that I want my element classes,
like "TotalWords", "TotalLines" to be visible only to the children of my main, "TextFile" class, that is once i
create an instance of a "TextFile" class should these
other classes be visible, to create details of a TextFile. Where in my code should i place these classes and also
their collection (wrapper classes).
The main problem i am facing is that, my Collections are
getting incremented multiple times, and i am in a big wreck
Thanks in Advance for any consideration
With Regards! Sunny


.



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

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