如何在ATL中进行继承 [英] How to do inheritance in ATL

查看:110
本文介绍了如何在ATL中进行继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我必须公开"ATL简单对象"界面.

现在,我想公开3个接口对象.每个功能都有一些通用功能,因此我试图将通用功能保留在抽象类中.

现在,我的要求是,每个三个类都应该有自己的方法,以及从通用抽象基类继承的通用功能[Lock之类的方法.]

请提出建议.

Hello Friends,

I have to expose "ATL simple object" interface.

Now, I wanted to expose 3 interface objects. Each one has some common functionality, hence I am trying to keep common functionality in abstract class.

Now, my requirement is that each three class should have their own methods plus common functionilty [methods like Lock] inherited from common abstract base class.


Please suggest. Helpfull link would really help.

推荐答案

您必须在IDL文件中定义一个接口,并在继承"该接口的所有ATL对象中实现该接口.

关于IDL,从这里开始:
]

关于实现接口:

http://msdn.microsoft.com/en-us/library/35tb9xw9 (v = vs.80).aspx [ http://stackoverflow.com/questions/2190993/创建一个atl-com-object-that-implements一个特定的接口 [
You have to define an interface in your IDL file, and implement it in all the ATL objects that ''inherit'' it.

About IDL, start here:
http://www.google.co.il/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CFcQFjAA&url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fwindows%2Fdesktop%2Fms690150(v%3Dvs.85).aspx&ei=fha6T_PeJNOg8gOPpeHJCg&usg=AFQjCNGyHC6ucN5yX0TXpX7PmNammxutig&sig2=Sufx_8vwOSaxqsftzdMtDA[^]

About implementing interfaces:

http://msdn.microsoft.com/en-us/library/35tb9xw9(v=vs.80).aspx[^]

http://stackoverflow.com/questions/2190993/creating-an-atl-com-object-that-implements-a-specific-interface[^]

Hope this helps,
Pablo.


除了给您提供参考的Pablo之外,您还可以参考Don Box的"Essential COM".它有点陈旧,但仍然有关COM编程的权威教程.

需要注意的另一件事...实现继承是您可以在两个类之间获得的最紧密的耦合形式.通过为类提供任何实现形式的公共基础,您就可以将基础与所有派生类 AND 耦合在一起,每个派生类又与其他每个派生类结合.如果要更改派生类之一的实现,则可能必须更改基类,这意味着对所有其他派生类进行隐式更改.

如果需要通用功能,请考虑使用自由功能和/或包含的对象来获得所需的效果.它将使您的设计不那么脆弱.

PS:刚想到,ATL使用的是Cimily Recursive Template模式,该模式最早由Jim Coplien在"The C ++ Report"之前记录.这是ATL架构的一项关键功能,因此可能值得一看.如果您想知道这是一种从基类调用派生类函数而不使用虚函数的方法.
In addition to the references Pablo''s given you have a look at "Essential COM" by Don Box. It''s a bit dated but still the definitive tutorial on COM programming.

Another thing to watch out for... Implementation inheritance is the tightest form of coupling you can get between two classes. By giving classes a common base with any form of implementation you''re coupling the base to all the derived classes AND each derived class to every other derived class. If you want to change an implementation of one of the derived classes then you might have to change the base class which means an implicit change to all the other derived classes.

If you want common functionality consider using free functions and/or a contained object to get the effect you want. It''ll make your design less fragile.

PS: Just thought, ATL uses the Curiously Recursive Template pattern first documented by Jim Coplien in "The C++ Report" yonks ago. It''s a key feature of ATL''s architecture so it might be worth looking it up. In case you''re wondering it''s a way of call derived class functions from a base class without using virtual functions.


这篇关于如何在ATL中进行继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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