接口,大不了!! [英] Interfaces, Big Deal!!
问题描述
请帮助我理解这一点,因为我不知道我错过了什么。
我在互联网上阅读了很多例子,解释说C#没有
实现多重继承,它实现了多个接口。
所以,我继续阅读阅读和阅读,看看如何通过界面解决我的
问题。
结论是我写信给你们所有人因为我不能找不到解决问题的方法
。
如果我可以创建多个接口而我必须在
$上实现这些方法b $ b派生类,然后是什么大不了。
我知道如果我声明一个继承自一个接口的类是有用的
因为例如
我可以创建一个名为Shape的接口,以及3个名为Circle的类,
Rectangle和Line。
如果在我的界面上我声明我的方法Draw();并且我在每个
派生类上实现然后我可以做下一个。
IShape s =(IShape)AnyShapeObject;
s.draw();
我觉得非常有用而且我多次使用过。但现在问题是什么
是多重继承和多个接口之间的相似之处?我没有看到太多
为什么在互联网上总是说多重继承和多个
接口就像他们有一个关系???
我的情况:
我有很多Windows控件,我继承了每一个用于创建我自己的
控件。
例如我想添加名为getVirtualSize()的方法;
我创建和接口
IVirtualSize
它包含
public getVirtualSize();
>
所以,在我的派生类上,我必须实现我的方法getVirtualSize,并且那是'
吧。
非常好!!! br />
现在真正的问题是,我在我的绘画方法上创造了很多逻辑;这个
逻辑对于所有派生类完全相同,为什么我必须在每个控件上实现这整个逻辑?
有了多个继承,你只需创建一个类
ExtendedControlFuncionality并实现OnPaintEx方法,而且我确实有一个很好的源代码,因为我的类ExtendedControlFuncionality有
所有新的扩展功能。
然后我怎么能用接口做同样的事情????
我不想把我的代码放在每个派生类上,这是一团糟
并且很难维护,我想集中我的源代码并在
同时我想使用基类的很多方法,这意味着我想要使用控件提供给我的所有受保护方法,因为
OnPaintEx需要那些。
真的,这里只有一个例子,现实是很多来源
代码我和q UOT;应该"在每个Control上实现,我不想这样做。
谢谢,答案将非常感谢。
Gustavo。
你好
与C ++不同,C#没有支持多实现继承。但是你的
问题可以通过从
Control派生类ExtendedControlFuncionality并从ExtendedControlFuncionality派生你的类来解决。
祝你好运,
Sherif
" Franco Gustavo" < GF ***** @ inuntius.com>在消息中写道
新闻:#h ************** @ tk2msftngp13.phx.gbl ...
请帮助我理解这一点,因为我不知道我错过了什么。
我在互联网上阅读了很多解释C#没有的例子实现多重继承它实现了多个接口。
所以,我一直在阅读,阅读和阅读,看看如何通过界面解决我的
问题。
结论是我写信给你们所有人,因为我找不到用
方法来解决我的问题。
如果我可以创建多个接口而我必须在派生类上实现方法
,那么什么是大问题。
我知道如果我声明一个继承自一个接口的类是有用的
因为例如
我可以创建一个名为Shape的接口,以及3个名为Circle,
Rectangle和Line的类。
如果在我的界面上我声明我的方法Draw();然后我就可以在每个派生类上实现,然后我可以做下一个。
IShape s =(IShape)AnyShapeObject;
s.draw();
我觉得非常有用,我多次使用过。但现在问题是多重继承和多个接口之间的相似性是什么?
我看不太多
为什么在互联网上总是说多重继承和多个
接口,就像他们有关系一样???
>我的案例:
我有很多Windows Control,我继承了每一个用于创建我自己的
控件。
例如我想添加方法叫做getVirtualSize();
我创建和界面
IVirtualSize
它包含
public getVirtualSize();
所以,在我的派生类中,我必须实现我的方法getVirtualSize和
就是它。
非常好!!!
>现在真正的问题是,我在我的绘画方法上创造了很多逻辑;这个
逻辑对于所有派生类完全相同,为什么我必须在每个控件上实现这整个逻辑?
有了多个继承,你只需要创建一个类
ExtendedControlFuncionality和实现一个方法OnPaintEx,而且我确实有一个很好的源代码,因为我的类ExtendedControlFuncionality具有所有新的扩展功能。
那怎么能我对接口做了同样的事情????
我不想把我的代码放在每个派生类上,这是一团糟
而且很难维护,我想要集中我的源代码和
同时我想使用基类的许多方法,这意味着我想要使用控件为我提供的所有受保护的方法
因为OnPaintEx需要那些。
真的,这里只有一个例子,现实是很多源代码,我应该。在每个Control上实现,我不想这样做。
谢谢,答案将非常感谢。
Gustavo。
你好
与C ++不同,C#不支持多个实现继承。但是你的
问题可以通过从
Control派生类ExtendedControlFuncionality并从ExtendedControlFuncionality派生你的类来解决。
祝你好运,
Sherif
" Franco Gustavo" < GF ***** @ inuntius.com>在消息中写道
新闻:#h ************** @ tk2msftngp13.phx.gbl ...
请帮助我理解这一点,因为我不知道我错过了什么。
我在互联网上阅读了很多解释C#没有的例子实现多重继承它实现了多个接口。
所以,我一直在阅读,阅读和阅读,看看如何通过界面解决我的
问题。
结论是我写信给你们所有人,因为我找不到用
方法来解决我的问题。
如果我可以创建多个接口而我必须在派生类上实现方法
,那么什么是大问题。
我知道如果我声明一个继承自一个接口的类是有用的
因为例如
我可以创建一个名为Shape的接口,以及3个名为Circle,
Rectangle和Line的类。
如果在我的界面上我声明我的方法Draw();然后我就可以在每个派生类上实现,然后我可以做下一个。
IShape s =(IShape)AnyShapeObject;
s.draw();
我觉得非常有用,我多次使用过。但现在问题是多重继承和多个接口之间的相似性是什么?
我看不太多
为什么在互联网上总是说多重继承和多个
接口,就像他们有关系一样???
>我的案例:
我有很多Windows Control,我继承了每一个用于创建我自己的
控件。
例如我想添加方法叫做getVirtualSize();
我创建和界面
IVirtualSize
它包含
public getVirtualSize();
所以,在我的派生类中,我必须实现我的方法getVirtualSize和
就是它。
非常好!!!
>现在真正的问题是,我在我的绘画方法上创造了很多逻辑;这个
逻辑对于所有派生类完全相同,为什么我必须在每个控件上实现这整个逻辑?
有了多个继承,你只需要创建一个类
ExtendedControlFuncionality和实现一个方法OnPaintEx,而且我确实有一个很好的源代码,因为我的类ExtendedControlFuncionality具有所有新的扩展功能。
那怎么能我对接口做了同样的事情????
我不想把我的代码放在每个派生类上,这是一团糟
而且很难维护,我想要集中我的源代码和
同时我想使用基类的许多方法,这意味着我想要使用控件为我提供的所有受保护的方法
因为OnPaintEx需要那些。
真的,这里只有一个例子,现实是很多源代码,我应该。在每个Control上实现,我不想这样做。
谢谢,答案将非常感谢。
Gustavo。
但是Control并没有做我想做的任何事情。
基本上,我想从Label,Panel,GroupBox派生,CheckBox,RadioButton,
等并添加我的扩展功能
Class控件没有任何功能。
>
在这种情况下,如果我从Control派生,我必须重写每个窗口
从头开始控制不可能,没有意义。
谢谢,
Gustavo。
" Sherif ElMetainy" < EL ************* @ wayout.net.NOSPAM>在消息中写道
news:%2 **************** @ TK2MSFTNGP11.phx.gbl ...Hello <与C ++不同,C#不支持多个实现继承。但
你的问题可以通过从Control派生类ExtendedControlFuncionality
并从ExtendedControlFuncionality派生你的类来解决。
祝你好运,
Sherif
" Franco Gustavo" < GF ***** @ inuntius.com>在消息中写道
新闻:#h ************** @ tk2msftngp13.phx.gbl ...
请帮助我理解这一点,因为我不知道我错过了什么。
我在互联网上阅读了很多解释C#没有的例子实现多重继承它实现了多个接口。
所以,我一直在阅读,阅读和阅读,看看如何通过界面解决我的
问题。
结论是我写信给你们所有人,因为我找不到解决问题的方法。
如果我可以创建多个接口而我必须在派生类上实现方法
然后有什么大不了的。
我知道如果我宣布一个类从一个接口继承是有用的
因为例如
我可以创建一个名为Shape的接口,并且可以调用3个类ed Circle,
Rectangle和Line。
如果在我的界面上我声明我的方法Draw();然后我就可以在每个派生类上实现,然后我可以做下一个。
IShape s =(IShape)AnyShapeObject;
s.draw();
我觉得非常有用,我多次使用过。但现在问题是
多重继承和多个
接口之间的相似之处是什么?我看不太多
为什么在互联网上总是说多重继承和多个界面就像它们有关系???
我的案例:
我有很多Windows Control,我会继承每一个用于创建我自己的
控件。
例如我想添加名为getVirtualSize()的方法;
我创建和界面
IVirtualSize
它包含
public getVirtualSize ();
所以,在我的派生类上,我必须实现我的方法getVirtualSize和
那个'blockquote class =post_quotes>它。
非常好!!!
现在真正的问题是,我在我的paint方法上创建了很多逻辑;
这个逻辑对于所有派生类完全相同,为什么我必须在每个控件上实现这个完整的逻辑?
有了多个继承,你只需要创建一个类
讯号分配延长dedControlFuncionality和实现一个方法OnPaintEx,真的是
我有一个很好的源代码,因为我的类ExtendedControlFuncionality
具有所有新的扩展功能。
然后我怎么能这样做有接口????
我不想把我的代码放在每个派生类上,这是一个
的混乱并且很难维护,我想集中我的源代码和
同时我想使用基类的许多方法,这意味着
我想使用控件提供给我的所有受保护方法
因为OnPaintEx需要那些。
真的,这里只有一个例子,现实是很多源代码,我应该。在每个Control上实现,我不想做
那个。
谢谢,答案将非常感谢。
Gustavo。
Hi,
Please help me to understand this, because I don''t see what I''m missing.
I was reading a lot of examples on Internet that explain that C# doesn''t
implement multiple inheritance it implement multiple interfaces.
So, I keep reading and reading and reading to see how can I resolve my
problem with interfaces.
The conclusion is I''m writing to all of you because I couldn''t find the way
to resolve my problem.
If I can create multiples interfaces and I have to implement the methods on
the derived class, then what''s the big deal.
I know if I declare a class that inherit from one interface is useful
because for example
I can create an Interface called Shape, and 3 Classes called Circle,
Rectangle, and Line.
If on my interface I declare my method Draw(); and I implement on each
derived class then I could do the next.
IShape s = (IShape) AnyShapeObject;
s.draw();
I think is very useful and I used many times. But now the question is what
is the similitude between Multiple Inheritance and Multiple Interfaces???? I
don''t see too much
Why on Internet always speak for Multiple Inheritance and Multiple
Interfaces like they have a relation???
My Case:
I have many Windows Control and I''m inherit each one for create my own
Controls.
For example I want to add method called getVirtualSize();
I create and interface
IVirtualSize
It contain
public getVirtualSize();
So, on my derived class I MUST implement my method getVirtualSize and that''s
it.
Very nice!!!
Now the real question is, I create a lot of logic on my paint method; this
logic is exactly the same for all derived classes, why do I have to
implement this entire logic on each Control???
With multiple inheritances you just create a class
ExtendedControlFuncionality and Implement a method OnPaintEx, and really I
have a nice source code, because my class ExtendedControlFuncionality has
all the new extended functionality.
Then how can I do the same with interfaces????
I don''t want to put my piece of code on every derived class, it is a mess
and very difficult to maintain, I want to centralize my source code and in
the same time I want to use many methods of the base classes, that means I
want to use all the protected methods that the controls offer to me because
OnPaintEx needs those.
Really, here is only one example, the reality is that is a lot of source
code that I "should" implement on every Control, I don''t want to do that.
Thanks, the answers will be really appreciated.
Gustavo.
Hello
Unlike C++, C# doesn''t support multiple implementaion inheritance. But your
problem can be solved by deriving the class ExtendedControlFuncionality from
Control and deriving your class from ExtendedControlFuncionality.
Best regards,
Sherif
"Franco Gustavo" <gf*****@inuntius.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...Hi,
Please help me to understand this, because I don''t see what I''m missing.
I was reading a lot of examples on Internet that explain that C# doesn''t
implement multiple inheritance it implement multiple interfaces.
So, I keep reading and reading and reading to see how can I resolve my
problem with interfaces.
The conclusion is I''m writing to all of you because I couldn''t find the way to resolve my problem.
If I can create multiples interfaces and I have to implement the methods on the derived class, then what''s the big deal.
I know if I declare a class that inherit from one interface is useful
because for example
I can create an Interface called Shape, and 3 Classes called Circle,
Rectangle, and Line.
If on my interface I declare my method Draw(); and I implement on each
derived class then I could do the next.
IShape s = (IShape) AnyShapeObject;
s.draw();
I think is very useful and I used many times. But now the question is what
is the similitude between Multiple Inheritance and Multiple Interfaces???? I don''t see too much
Why on Internet always speak for Multiple Inheritance and Multiple
Interfaces like they have a relation???
My Case:
I have many Windows Control and I''m inherit each one for create my own
Controls.
For example I want to add method called getVirtualSize();
I create and interface
IVirtualSize
It contain
public getVirtualSize();
So, on my derived class I MUST implement my method getVirtualSize and that''s it.
Very nice!!!
Now the real question is, I create a lot of logic on my paint method; this
logic is exactly the same for all derived classes, why do I have to
implement this entire logic on each Control???
With multiple inheritances you just create a class
ExtendedControlFuncionality and Implement a method OnPaintEx, and really I
have a nice source code, because my class ExtendedControlFuncionality has
all the new extended functionality.
Then how can I do the same with interfaces????
I don''t want to put my piece of code on every derived class, it is a mess
and very difficult to maintain, I want to centralize my source code and in
the same time I want to use many methods of the base classes, that means I
want to use all the protected methods that the controls offer to me because OnPaintEx needs those.
Really, here is only one example, the reality is that is a lot of source
code that I "should" implement on every Control, I don''t want to do that.
Thanks, the answers will be really appreciated.
Gustavo.
Hello
Unlike C++, C# doesn''t support multiple implementaion inheritance. But your
problem can be solved by deriving the class ExtendedControlFuncionality from
Control and deriving your class from ExtendedControlFuncionality.
Best regards,
Sherif
"Franco Gustavo" <gf*****@inuntius.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...Hi,
Please help me to understand this, because I don''t see what I''m missing.
I was reading a lot of examples on Internet that explain that C# doesn''t
implement multiple inheritance it implement multiple interfaces.
So, I keep reading and reading and reading to see how can I resolve my
problem with interfaces.
The conclusion is I''m writing to all of you because I couldn''t find the way to resolve my problem.
If I can create multiples interfaces and I have to implement the methods on the derived class, then what''s the big deal.
I know if I declare a class that inherit from one interface is useful
because for example
I can create an Interface called Shape, and 3 Classes called Circle,
Rectangle, and Line.
If on my interface I declare my method Draw(); and I implement on each
derived class then I could do the next.
IShape s = (IShape) AnyShapeObject;
s.draw();
I think is very useful and I used many times. But now the question is what
is the similitude between Multiple Inheritance and Multiple Interfaces???? I don''t see too much
Why on Internet always speak for Multiple Inheritance and Multiple
Interfaces like they have a relation???
My Case:
I have many Windows Control and I''m inherit each one for create my own
Controls.
For example I want to add method called getVirtualSize();
I create and interface
IVirtualSize
It contain
public getVirtualSize();
So, on my derived class I MUST implement my method getVirtualSize and that''s it.
Very nice!!!
Now the real question is, I create a lot of logic on my paint method; this
logic is exactly the same for all derived classes, why do I have to
implement this entire logic on each Control???
With multiple inheritances you just create a class
ExtendedControlFuncionality and Implement a method OnPaintEx, and really I
have a nice source code, because my class ExtendedControlFuncionality has
all the new extended functionality.
Then how can I do the same with interfaces????
I don''t want to put my piece of code on every derived class, it is a mess
and very difficult to maintain, I want to centralize my source code and in
the same time I want to use many methods of the base classes, that means I
want to use all the protected methods that the controls offer to me because OnPaintEx needs those.
Really, here is only one example, the reality is that is a lot of source
code that I "should" implement on every Control, I don''t want to do that.
Thanks, the answers will be really appreciated.
Gustavo.
But Control doesn''t do anything that I want.
Basically, I want derive from Label, Panel, GroupBox, CheckBox, RadioButton,
etc. and add my extended funcionalities
The Class control doesn''t have any funcionality.
On that case if I derived from Control I have to rewrite each windows
control from scratch wich is "not possible", doesn''t make sense.
Thanks,
Gustavo.
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...Hello
Unlike C++, C# doesn''t support multiple implementaion inheritance. But your problem can be solved by deriving the class ExtendedControlFuncionality from Control and deriving your class from ExtendedControlFuncionality.
Best regards,
Sherif
"Franco Gustavo" <gf*****@inuntius.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...Hi,
Please help me to understand this, because I don''t see what I''m missing.
I was reading a lot of examples on Internet that explain that C# doesn''t
implement multiple inheritance it implement multiple interfaces.
So, I keep reading and reading and reading to see how can I resolve my
problem with interfaces.
The conclusion is I''m writing to all of you because I couldn''t find the wayto resolve my problem.
If I can create multiples interfaces and I have to implement the methods
onthe derived class, then what''s the big deal.
I know if I declare a class that inherit from one interface is useful
because for example
I can create an Interface called Shape, and 3 Classes called Circle,
Rectangle, and Line.
If on my interface I declare my method Draw(); and I implement on each
derived class then I could do the next.
IShape s = (IShape) AnyShapeObject;
s.draw();
I think is very useful and I used many times. But now the question is what is the similitude between Multiple Inheritance and Multiple Interfaces???? Idon''t see too much
Why on Internet always speak for Multiple Inheritance and Multiple
Interfaces like they have a relation???
My Case:
I have many Windows Control and I''m inherit each one for create my own
Controls.
For example I want to add method called getVirtualSize();
I create and interface
IVirtualSize
It contain
public getVirtualSize();
So, on my derived class I MUST implement my method getVirtualSize and
that''sit.
Very nice!!!
Now the real question is, I create a lot of logic on my paint method;
this logic is exactly the same for all derived classes, why do I have to
implement this entire logic on each Control???
With multiple inheritances you just create a class
ExtendedControlFuncionality and Implement a method OnPaintEx, and really I have a nice source code, because my class ExtendedControlFuncionality has all the new extended functionality.
Then how can I do the same with interfaces????
I don''t want to put my piece of code on every derived class, it is a mess and very difficult to maintain, I want to centralize my source code and in the same time I want to use many methods of the base classes, that means I want to use all the protected methods that the controls offer to me
becauseOnPaintEx needs those.
Really, here is only one example, the reality is that is a lot of source
code that I "should" implement on every Control, I don''t want to do that.
Thanks, the answers will be really appreciated.
Gustavo.
这篇关于接口,大不了!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!