0
votes
1answer
138 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 ...
1
vote
2answers
65 views

Inheritance vs 'specification' by fields

I'm currently reading 'Head first design patterns', and already the first chapter threw some questions towards me. This chapter introduces the 'prefer composition over inheritance' design principle, ...
1
vote
2answers
117 views

Alternatives to inheritance on complex structures?

I'm working on an ASP.NET Webforms project, using the MVP Pattern (which the presenters as you may know use a Page Controller pattern). I'm given a rather complex inheritance chain for my controllers. ...
3
votes
3answers
111 views

Why should one subclass instead of composite when using the Factory Method design pattern?

I'm currently learning about design patterns. I learned about the Factory Method pattern. This pattern means that in order to implement a factory to create objects, one should subclass the class that ...
3
votes
3answers
373 views

Why is inheritance only defined at compile-time?

I found this statement from the gang of four's "Design Patterns" particularly odd; for some context, the authors are comparing inheritance versus composition as reuse mechanisms [p. 19]: "...you ...
3
votes
2answers
199 views

Help with inheritance hierarchy design

I'm having trouble designing an inheritance hierarchy. In the figure: Base class: This uses the Template Method. Contains core logic/algorithm that calls virtual/abstract methods Derived ...
3
votes
2answers
179 views

which pattern to use - if at all

I am fairly new to using patterns and although I understand some of them to a point I find it difficult to work out which one(s) to use in a particular situation. I am trying to wrap up an existing ...
3
votes
2answers
274 views

Base class should have no knowledge of its subtypes?

What's the OO principle that states (in sum): A base object should have no knowledge of its subtypes. I thought it was Liskov Substitution but after reading that wikipedia article I don't ...
1
vote
4answers
462 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 ...
1
vote
3answers
318 views

Does non-virtual-by-default lead us to composition-over-inheritance?

There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
1
vote
2answers
363 views

What principle of OOAD is this pattern breaking?

I'm trying to make a case for not putting the structure in the parent BaseModule class I've shown below. I'm more for a Strategy Pattern, and minimizing inheritance in favor of has-a relationships, ...
2
votes
2answers
223 views

Template method within one class without subclasses or inheritance

I have an algorithm with mostly invariant parts that needs to be reused within one class so as to stay DRY. Code duplication with repeating method structure public void save(String key, int value) ...
3
votes
2answers
815 views

Alternative to “inheritance versus composition?” [duplicate]

Possible Duplicate: Where does this concept of “favor composition over inheritance” come from? I have colleagues at work who claim that "Inheritance is an anti-pattern" and want to use ...
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, ...
7
votes
6answers
2k views

Why is subclassing too much bad (and hence why should we use prototypes to do away with it)?

I was reading up on design patterns, and I read that the prototype design pattern does away with excessive subclassing. Why is subclassing bad? What advantage would using a prototype bring about over ...
0
votes
2answers
234 views

Inheritance versus Composition in a business application

I have a training management and tracking system, with a high level structure as follows: We have a Role1, e.g. Manager, Shift-boss, miner, etc. and a Candidate, training for that Role. The role has ...
7
votes
6answers
3k views

When you use inheritance to reuse code, do you find it too tricky that it swallows the benifits of reuse?

I've been coding for about 8 years, however I still find inheritance is too flexible and sometimes it makes you totally confused with the code you have written. One simplest example would be: ...