OOP - OOD问题 [英] OOP - OOD Question

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

问题描述

让我们说我有一个班级


班级基础类

{

...

public int someProperty

{

....

}

}


现在我创建了新的类,我使用了someProperty,但是我不希望我班级的

用户使用它,而不是设计时间,不是实时....

let''s say i have a class

class baseclass
{
...
public int someProperty
{
....
}
}

and now i create new class, there i use "someProperty", but don''t want the
users of my class use it, not in design time, not in real time....

推荐答案

你是什么意思看到?智能感知?属性窗口?


一个明显的解决方案是将属性声明为私有或朋友,但

你可能已经想到了这一点。 :-)


-

Greetz


Jan Tielens

________________________________

阅读我的博客: http://weblogs.asp.net/jan

David Ichilov <哒******* @ hotmail.com>在消息中写道

新闻:eX ************** @ TK2MSFTNGP10.phx.gbl ...
What do you mean by "see"? Intellisense? Properties window?

An obvious solution would be to declare the property private or friend, but
you''ve probably figured that yourself. :-)

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"David Ichilov" <da*******@hotmail.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
让我们说我有一个班级

班级基础类
{
...
public int someProperty
{
....
现在我创建了一个新类,我使用了someProperty,但不希望我班级的
用户使用它,而不是设计时间,而不是实时......
let''s say i have a class

class baseclass
{
...
public int someProperty
{
....
}
}

and now i create new class, there i use "someProperty", but don''t want the
users of my class use it, not in design time, not in real time....



David,
David,
let''我说我有一个班级

班级基础类
{
...
public int someProperty
{
....
}
}

现在我创建了新的类,我使用了someProperty,
但不希望我班级的用户使用它,而不是在设计中
时间,而不是实时....
let''s say i have a class

class baseclass
{
...
public int someProperty
{
....
}
}

and now i create new class, there i use "someProperty",
but don''t want the users of my class use it, not in design
time, not in real time....




很难猜到你在这里得到了什么。

必然是一个适合您情况的理想架构。并且有一个相当高的百分比,我不会猜对了。但是一种方法是:


抽象类基类

{

public abstract int someProperty {get; }

}


密封类newclass:baseclass

{

public override int someProperty

{

get

{

返回1;

}

}

}


class newclassForUser:baseclass

{

public override int someProperty

{

get

{

返回0;

}

}

}


这样可以防止用户继承你的密封消息。类和行为。

它还使它们实现了自己的someProperty版本。但是那个

可能是微不足道的,从未使用过。


希望在某种程度上有所帮助。


问候,


兰迪



It''s difficult to guess at what you are getting at here. There is bound to
be an ideal architecture that fits your situation. And there is a pretty
high percentage that I will not guess the right one. But one approach is:

abstract class baseclass
{
public abstract int someProperty{ get; }
}

sealed class newclass : baseclass
{
public override int someProperty
{
get
{
return 1;
}
}
}

class newclassForUser : baseclass
{
public override int someProperty
{
get
{
return 0;
}
}
}

This keeps the user from inheriting from your "sealed" class and behavior.
It also makes them implement their own version of "someProperty," but that
can be trivial and never used.

Hope that helps in some way.

Regards,

Randy


以什么方式使用它?


查看它,修改它,设置它?这些都不是吗?


如果用户绝对无法访问该物业,那么将其设为

私人。


如果你希望他们只是能够查看它而不是更改它的财产

这样做。


class baseclass

{

private int InternalValue;

public int someProperty

{

get

{

返回InternalValue;

}

}

}


如果你希望他们只能设置值但不能读取它,那么请执行

这个:


class baseclass

{

private int InternalValue;

public int someProperty

{

set

{

InternalValue =返回;

}

}

}


我想不出还有什么意思但不能使用它?


希望我帮助过了...


Simon。


David Ichilov " <哒******* @ hotmail.com>在消息中写道

新闻:eX ************** @ TK2MSFTNGP10.phx.gbl ...
Use it in what way?

View it, Modify it, Set it? None of these?

If the user to have absolutely no access to the property then make it
private.

If you want them to just be able to view it but not change it the property
do this.

class baseclass
{
private int InternalValue;
public int someProperty
{
get
{
return InternalValue;
}
}
}

If you want them to be able just to set the value but not to read it then do
this:

class baseclass
{
private int InternalValue;
public int someProperty
{
set
{
InternalValue = return;
}
}
}

I can''t think what else you''d mean but not use it?

Hope I''ve helped :)

Simon.

"David Ichilov" <da*******@hotmail.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
让我们说我有一个班级

班级基础类
{
...
public int someProperty
{
....
现在我创建了一个新类,我使用了someProperty,但不希望我班级的
用户使用它,而不是设计时间,而不是实时....
let''s say i have a class

class baseclass
{
...
public int someProperty
{
....
}
}

and now i create new class, there i use "someProperty", but don''t want the
users of my class use it, not in design time, not in real time....



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

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