关于接口的建议 [英] advice about Interfaces

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

问题描述




我开始开发门户网站,过去我从未使用过接口。


因为任何门户网站都是可能的注册(添加),删除,修改用户。

在这个门户中也可以注册(添加),删除,修改

商务...

我有一个名为user的类,另一个名为bussiness ...


昨天我正在阅读有关接口的使用并给我一个

想法,但我不知道它是否是一个好方法:


主题是,使3个界面具有IRegistrable,IModifiable,IRemovable


并将这三个实现为两个类,User和Bussiness。


在每个接口内部有一个方法:


IRegistrable使用一个名为Register()的方法

使用一个名为Modify()的方法进行IModifiable

IRemovable使用一个名为Remove的方法()


有关它的建议吗?

--------

谢谢

问候。

Josema

Hi,

Im starting develop a portal, and i never used interfaces in the past.

As any portal will be possible register (add), delete, modify a user.
In this portal also will be possible register(add) , delete, modify
bussiness...
I have a class called user, and another called bussiness...

Yesterday i was reading about the using of the interfaces and gives to me an
idea, but i dont know if its a good way to do:

the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()

Any advice about it?
--------
Thanks
Regards.
Josema

推荐答案

" Josema" <济****** @ ocu.org> écritdansle message de news:
D9 ********************************** @ microsoft.com ...
"Josema" <Je******@ocu.org> a écrit dans le message de news:
D9**********************************@microsoft.com...
主题是,使3个界面具有可互换性,可修改性,可移动性和/或实现这三个进入两个类,User和商业。

在每个界面内有一个跟随此的方法:

IRegistrable与一个名为Register()的方法
可修改一个名为Modify()的方法
使用名为Remove()的方法的IRemovable
the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()



但这意味着您要向类添加注册,修改和删除行为

,不是Portal。


如果你想在Portal后面有不同的实现,

然后用你的三种方法声明一个接口IPortal将是

值得,但除此之外,我看不出太多的意思。


Joanna


-

Joanna Carter

顾问软件工程师



But this means that you are adding the Register, Modify and Remove behaviour
to the classes, not to the Portal.

If you are thinking of having differing implementations behind the Portal,
then declaring an interface IPortal with your three methods would be
worthwhile, but apart from that, I cannot see too much point.

Joanna

--
Joanna Carter
Consultant Software Engineer


嗨Joanna,我不明白当你谈到

类的行为时...我认为如果两个对象具有相同的操作(对象

人,并且对象业务可以注册,修改,删除等等...),

可以很好地在其中实现一些接口...


我不明白这个人是不是而商业可以是例如,

注册,我没有看到与门户网站的关系,门户网站不能

注册....


你能解释一下吗?


很抱歉我对接口的使用不了解新手......


亲切的问候。

Josema。


" Joanna Carter(TeamB)"写道:
Hi Joanna, i dont understand when you talk about the behaviour of the
classes... I thought that if two objects has the same operations (object
person, and object bussiness can be registered, modified, removed, etc...),
could be good to make some interfaces to implement inside of them...

I dont understand if the person and the bussiness can be for instance,
registered, i dont see the relation with the portal, the portal cant be
registered....

Could you explain it a little?

Sorry for my not understanding im newbie in the using of the interfaces...

Kind Regards.
Josema.

"Joanna Carter (TeamB)" wrote:
" Josema" <济****** @ ocu.org> a ??? crit dans le message de news:
D9 ************** @微软。 com ...
"Josema" <Je******@ocu.org> a ??crit dans le message de news:
D9**********************************@microsoft.com...
主题是,使3个界面具有可线性,可修改性,IRemovable

并将这三个实现到两个类中,用户和/或商业。

在每个接口内部有一个方法:

IRegistrable与一个名为Register()的方法
可以使用一个名为Modify()的方法进行IModifiable使用名为Remove()的方法的IRemovable
the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()



但这意味着您要向类中添加注册,修改和删除行为,而不是添加到Portal。如果你想在Portal后面有不同的实现,
那么用你的三种方法声明一个IPortal界面将是值得的,但除此之外,我看不到太多Joanna

- Joanna Carter
Co顾问软件工程师



But this means that you are adding the Register, Modify and Remove behaviour
to the classes, not to the Portal.

If you are thinking of having differing implementations behind the Portal,
then declaring an interface IPortal with your three methods would be
worthwhile, but apart from that, I cannot see too much point.

Joanna

--
Joanna Carter
Consultant Software Engineer



" Josema" <济****** @ ocu.org> écritdansle message de news:
C1 ********************************** @ microsoft.com ...
"Josema" <Je******@ocu.org> a écrit dans le message de news:
C1**********************************@microsoft.com...
嗨Joanna,我不明白你什么时候谈论
类的行为......我想如果两个对象有相同的操作(对象
人,对象业务可以注册,修改,删除,
等...),可以很好地在其中实现一些接口...
注册,我没有看到与门户网站的关系,门户网站不能注册....


我从你的发帖地址假设你自己的语言可能是

西班牙语?


这是否意味着我会改变你的方法姓名:


注册 - 保存或存储

修改 - 更改或更新

删除 - 删除


....并且这些方法用于存储和检索来自某些数据库或文件的对象?


如果是这样的话是这样的,那么你不想把这些方法放在对象中你将会做这些事情。它们真的属于你所谓的b $ b b调用一个Portal。


你的Portal应该能够检查传递给它的对象而不用

必须改变那些对象。在.NET中,这意味着你可以使用反射来从对象读取/写入值。


所以,你只需要将方法添加到你的门户网站是这样的:


界面IPortal

{

void注册(对象obj);

void修改(对象obj);

void删除(对象obj);

}


将使用这样的:


{

IPortal portal = new DatabasePortal(); //或者你想要使用的任何类型

...

人物=新人();

...

portal.Register(person)

...

}


现在为Portal声明一个界面允许您更改用于注册,修改和删除对象的类




但是按照建议声明接口没有任何优势并且

在要传递给Portal的对象上使用它们。

很抱歉我对接口的使用不了解新手......
Hi Joanna, i dont understand when you talk about the behaviour of the
classes... I thought that if two objects has the same operations (object
person, and object bussiness can be registered, modified, removed, etc...), could be good to make some interfaces to implement inside of them...

I dont understand if the person and the bussiness can be for instance,
registered, i dont see the relation with the portal, the portal cant be
registered....
I assume from your posting address that your own language would possibly be
Spanish ?

Does that mean that I couold change your method names to :

Register - Save or Store
Modify - Change or Update
Remove - Delete

....and that these methods are for storing and retrieving objects from some
kind of database or file ?

If that is the case, then you don''t want to put these methods in the objects
that you are going to do these things to; they really belong in what you
call a Portal.

Your Portal should be able to examine the objects passed to it without
having to change those objects. In .NET that means you can use reflection to
read/write values from/to the objects.

So, you just need to add the methods to your Portal like this :

interface IPortal
{
void Register(object obj);
void Modify(object obj);
void Remove(object obj);
}

Which would be used like this :

{
IPortal portal = new DatabasePortal(); // or whatever type you want to use
...
Person person = new Person();
...
portal.Register(person)
...
}

Declaring an interface for the Portal now allows you to change the class
that you use to Register, Modify, and Remove objects.

But there is no advantage in declaring the interfaces as you suggest and
using them on the objects to be passed to the Portal.
Sorry for my not understanding im newbie in the using of the interfaces...




而且我认为你试图在错误的地方使用它们并且出错了

原因:-)


Joanna


-

Joanna Carter

顾问软件工程师



And I think you are trying to use them in the wrong place and for the wrong
reason :-)

Joanna

--
Joanna Carter
Consultant Software Engineer


这篇关于关于接口的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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