I have a problem to understand how to solve parallel inheritance.
Definition of Parallel Inheritance
Fowler definies parallel inheritance as follows [1, page 68]:
Parallel inheritance hierarchies is really a special case of shotgun surgery. In this case, every time you make a subclass of one class, you also have to make a subclass of another. You can recognize this smell because the prefixes of the class names in one hierarchy are the same as the prefixes in another hierarchy.
Problem
In the Book Refactoring in Large Software Projects: Performing Complex Restructurings, page 46 the author displays the following parallel inheritance:
Then he solves the parallel inheritance with composition and says:
In many cases, parallel inheritance hierarchies can be resolved in such a manner that only one inheritance hierarchy is left, while the classes of other inheritance hierarchies are integrated through use.
The solution looks like this:
So the author and Fowler concludes that a parallel inheritance can be solved with
The general strategy for eliminating the duplication is to make sure that instances of one hierarchy refer to instances of the other.
The problem which I see is the classes are still there and if I add a new class a new '*ListView' class must be added.
But for this problem Fowler says:
If you use Move Method and Move Field, the hierarchy on the referring class disappears.
For the current case this means I move the method to display the entities in the entity classes?
So this will hurts the MVC principal or not?!
QUESTION
So how to solve parallel inheritance at all and especially in UI cases?
SOURCE:
1 Martin Fowler 'Refactoring: Improving the Design of Existing Code'
[Book: Refactoring in Large Software Projects: Performing Complex Restructurings, page 46]