473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Define an interface hierarchy?

Hello!

I have a class hierarchy that consists mainly of one base class
CtxBase, and two children: LoginCtx and DisconnectCtx.

Now, there's a need to provide an interfaces for this hierarchy. I'd
like to export this classes from a DLL.
And I'm in doubt how can I achieve this?

My first option was to define a base interface (ICtxBase) and then
derive both ILoginCtx and IDisconnectCtx from it. But using this
approach I get ambiguous calls inside derived classes, cause the
inherit from both their specific interfaces and the base classs,
making the base interface ICtxBase to appear in the hierarchy twice.

Can anyone tell me, is there a standard approach for such situation?

Thanks!
Sep 5 '08 #1
2 1652
Anton Bredikhin wrote:
[..]
Now, there's a need to provide an interfaces for this hierarchy. I'd
like to export this classes from a DLL.
And I'm in doubt how can I achieve this?
[..]
DLLs are off-topic since they are not features of the language. They
are platform-specific and thus please post to the newsgroup that deals
with programming your platform. 'comp.os.ms-windows.programmer' comes
to mind. Also, consider posting to the newsgroup for the compiler
you're using since "exporting" a class is most likely a language
extension provided by your compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 5 '08 #2
On Sep 5, 11:24 am, Anton Bredikhin <duud...@gmail.comwrote:
Hello!

I have a class hierarchy that consists mainly of one base class
CtxBase, and two children: LoginCtx and DisconnectCtx.

Now, there's a need to provide an interfaces for this hierarchy. I'd
like to export this classes from a DLL.
And I'm in doubt how can I achieve this?

My first option was to define a base interface (ICtxBase) and then
derive both ILoginCtx and IDisconnectCtx from it. But using this
approach I get ambiguous calls inside derived classes, cause the
inherit from both their specific interfaces and the base classs,
making the base interface ICtxBase to appear in the hierarchy twice.
Why would you inherit from an interface to blueprint your derived
classes?
Ask yourself if DisconnectCtx is_a interface?

Sshow a simple reconstruction of the problem you have.
How difficult could that be?

#include <iostream>

class ICtx
{
public:
virtual void foo() const { std::cout << "ICtx::foo()\n"; }
};

class ILoginCtx : public ICtx { };

class Ctx
{
public:
virtual void login(const ILoginCtx& ri) = 0;
};

void Ctx::login(const ILoginCtx& ri)
{
std::cout << "Ctx::login()\n";
ri.foo();
}

class LoginCtx : public Ctx
{
public:
virtual void login(const ILoginCtx& ri)
{
std::cout << "LoginCtx::login()\n";
Ctx::login(ri);
}
};

int main()
{
LoginCtx ctx;
ILoginCtx interface;
ctx.login( interface );
}
>
Can anyone tell me, is there a standard approach for such situation?

Thanks!
First thought that comes to mind is that you have a potential design
issue. One class appears to be responsible for Logins and another for
Disconnects? Wouldn't it make more sense that a SessionCtx class and
its derivatives handle both connects and disconnects, perhaps each
derivative does that in a different way?
Sep 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Simon Harvey | last post by:
Festive greetings fellow programmers! I've been programming now for about 4, maybe 5 years now. 4 of those years were at university so and I havent had much work experience of making real world...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
12
by: Meya-awe | last post by:
I am puzzled, what is the purpose of an interface? How does it work, what i mean is how does the compiler treats this? Why when we talk about separating user interface from business logic, an...
12
by: masoud bayan | last post by:
I've come across something in Interface implementation that I am not sure is correct behavior in VB.NET (and maybe C#) or not? Consider following example: Public Interface IShape
15
by: mr.peteryu | last post by:
Hi, Can someone explain the idea behind casting to an interface? For example: -> I have an IInterface that contains a Read() method. -> I have an object "obj" that implements IInterface. ...
6
by: Zach | last post by:
Hi everyone, I'm a bit of a newbie to C# programming so forgive this innocent question, but coming from a C++ background this seems very odd to me, and I'm hoping someone can shed some light...
17
by: Zytan | last post by:
Aren't all classes interfaces? What constitutes an interface (and with it, the "I" prefix distinction)? Zytan
1
by: newbie | last post by:
Here is my question: I want to have a class, which requires a typename T with interface "operate()" and "Init()" as its parameter. template <class Tclass Foo { public: Foo(int param) {...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.