|
INTERVIEW QUESTIONS
C++
C++ BASICS
DETAILS
Question: From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?
Answer: With regard to versioning, interfaces are less flexible than classes. With a class, you can ship version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method.
|
|
|
Category |
C++ Basics Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8433 users |
Added on |
10/24/2009 |
Views |
75634 |
Rate it! |
|
|
Question:
From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?
Answer:
With regard to versioning, interfaces are less flexible than classes. With a class, you can ship version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How is method overriding different from overloading?
|
View Answer
|
|
What is a class?
|
View Answer
|
|
What is an object?
|
View Answer
|
|
What is the difference between class and structure?
|
View Answer
|
|
What is the difference between an object and a class?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C++ Basics Interview Questions & Answers - Exam Mode /
Learning Mode
|