Tagged Questions
0
votes
0answers
124 views
Inheritance vs interface [closed]
I know that this isn't new question, and even few (but far more specific) similar ones were asked here. But I want to ask you something in general meaning, not relating to any concrete case.
Few days ...
2
votes
1answer
144 views
Code re-use in C++, via multiple inheritance or composition? Or…?
I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes.
If you’re defining a hierarchy of abstract ...
1
vote
1answer
160 views
Should I use inheritance or an interface?
So in a nutshell I have an abstract class :
public abstract class Member
{
public string PCode { get; set; }
public string Reference { get; set; }
public DateTime? ElectedDate { get; set; }
}
And ...
0
votes
1answer
93 views
When is it suitable to use inheritance [duplicate]
I recently had a small "argument" about inheritance with a friend. I think people overuse it a lot. Intuition tells me that that the only good reason for class inheritance is polymorphism - when there ...
1
vote
3answers
243 views
Why are inheritance and interfaces restricted to instance members?
Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language.
I think that the use of attributes and ...
2
votes
1answer
146 views
Using partially implemented interfaces
Consider the following hierarchy in C++ notation:
class A
{
public:
virtual void doStuff()=0;
virtual void doOtherStuff()=0;
};
class B:public A
{
public:
...
11
votes
12answers
2k views
Is “If a method is re-used without changes, put the method in a base class, else create an interface” a good rule-of-thumb?
A colleague of mine came up with a rule-of-thumb for choosing between creating a base class or an interface.
He says:
Imagine every new method that you are about to implement. For each of them, ...
4
votes
1answer
288 views
Is using protected inheritance to hide (but exploit) implemented interface from the public ok?
Recently, we had a discussion about code using protected inheritance in order to hide the fact (to client code) a class inherits from a specific base class but to exploit this fact in the ...
1
vote
4answers
523 views
Explanation of the definition of interface inheritance as described in GoF book
I am reading the first chapter of the Gof book. Section 1.6 discusses about class vs interface inheritance:
Class versus Interface Inheritance
It's important to understand the difference between ...
7
votes
9answers
1k views
What OO Design to use ( is there a Design Pattern )?
I have two objects that represent a 'Bar/Club' ( a place where you drink/socialise).
In one scenario I need the bar name, address, distance, slogon
In another scenario I need the bar name, address, ...
3
votes
2answers
842 views
Is it a good programming practice to have a class with several .h files?
I suppose the class have several different interfaces. Some it shows to some class, some it shows to other classes.
Are there any good reason for that?
One thing I can think of is with one .h per ...
8
votes
5answers
2k views
Interface and Inheritance: Best of both worlds?
I 'discovered' interfaces and I started to love them. The beauty of an interface is that it is a contract, and any object that fulfills that contract can be used wherever that interface is required.
...
26
votes
4answers
12k views
Why should I prefer composition over inheritance?
I always read that composition is to be preferred over inheritance. A blog post on unlike minds, for example, advocates using composition over inheritance, but I can't see how polymorphism is ...
24
votes
9answers
3k views
Are abstract classes / methods obsolete?
I used to create a lot of abstract classes / methods. Then I started using interfaces.
Now I am not sure if interfaces aren't making abstract classes obsolete.
You need a fully abstract class? ...
4
votes
9answers
753 views
Does single inheritance limit what we can do with generalisation?
As a rule of thumb, generalisation is used only in specific circumstances. For example, when we can say that X is literally a subclass of Y. So, we can happily say that a Horse is a subclass of ...
0
votes
5answers
1k views
Why does the use of interface-based programming appear to be limited to behaviour?
I have been doing a little thinking about inheritance vs. realization vs. composition. I am not about to post the whole detail here. So I was wondering, when we are not talking about creating ...