By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,333 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,333 IT Pros & Developers. It's quick & easy.

How can we implement third party class, with out inheritance ?

P: 9
How can we implement third party class, with out using inheritance ?

class thirdPartyClass
{
virtual void func1();
virtual void func2();
};

class sample
{


};

I want to implement the member functions of class thirdPartyClass , without using inheritance in sample class.
Jun 12 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
You can never implement the methods of one class in another class.

The most you can do is:

1) override the methods of the thirdPartyClass by the sample class but this requires inheritance.

2) hide the methods of the thirdPartyClass by a method inthe sample class but this also requires inheritance.

However, you can cheat. You can use the Adapter design pattern. In this pattern you have sample contain a thirdPartyClass object as a private member. You then write methods on sample that may, or may not, use thirdPartyClass methods. The sample methods could even have the same names and arguments as thethirdPartyClass methods to further obscure what you are doing.
Jun 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.