473,769 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1678
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.program mer' 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(cons t ILoginCtx& ri)
{
std::cout << "Ctx::login()\n ";
ri.foo();
}

class LoginCtx : public Ctx
{
public:
virtual void login(const ILoginCtx& ri)
{
std::cout << "LoginCtx::logi n()\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
2272
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 applications (although I trying to make some now). There is still a lot I don't know when it comes to making programs. I know all the theory, but not how (and why) certain things are done in real world projects. My current ponderings are about...
9
4650
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
7558
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 be implemented. So if you have a class which inherits base class that inherts an interface, then your classes will have a standard. I suppose you can also check for interface at run time say when dll is loaded and see if it implememts whats...
12
2844
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 interface is declared, what is it's purpose? thanks, BRAMOIN *** Sent via Developersdex http://www.developersdex.com ***
12
1306
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
26300
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. Why would someone do the following and what does it mean?
6
1499
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 onto why things work this way as opposed to the C++ way, which I see no real disadvantages in. The issue arises when trying to implement an interface in C#. In C++ it is quite common to define an interface using a bunch fo pure virtual functions...
17
2284
by: Zytan | last post by:
Aren't all classes interfaces? What constitutes an interface (and with it, the "I" prefix distinction)? Zytan
1
1485
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) { _algorithm.Init(param); } void do_algorithm(vector<inta) { _algorithm.operate(a); ....
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.