1. According to Fowler's definition this pattern is implemented by having all classes in a layer inherit from a superclass. But after some googling it appears all of the following are considered as implementations of a Layer Supertype pattern:

a - all classes in a layer inheriting from the same superclass
b - having only some ( thus not all ) of classes in a layer inheriting from a superclass
c - layer having superclasses S1 and S2, where classes A and B inherit from S1, while C inherits from S2

So which of above are considered as implementations of a Layer Supertype?

2. If a,b and c are all considered implementations of a Layer SuperType, then I fail to see how this pattern is any different from a regular class inheritance. In other words, couldn't we then claim we're using Layer Supertype any time some class inherits from another class?


  • Your second question suffers from the logical fallacy "If A then B; B, therefore A". Say class M is in layer 1 and class N is in layer 2 and they both derive from class S; they're not following the Layer Supertype pattern since they're in different layers, even though they inherit from the same superclass. – paul Jun 19 '13 at 19:16
  • @paul: I don't quite understand your point, since my second question assumes that all M, N and S are in the same layer?! – EdvRusj Jun 20 '13 at 17:06
  • I hadn't caught that you were thinking they'd all be in the same layer as part of that question; the way you phrased it made me think you meant any and all inheritance in general. – paul Jun 20 '13 at 17:10

As defined by Fowler, only a would be a Layer Supertype. However, people consider the others Layer Supertypes in that they are specific to a layer--all of the subtypes of the supertype must exist and be relavant to the same layer.

Consider, for example, the view layer in an MVC application. You might have the windows or pages all extend a single supertype, but also have helper classes or strategy classes that also live in the layer to support the view. The supertype is very much tied to the layer, in this case, even though it does not underlie everything. I don't think it's wrong to call this a layer superclass.

| improve this answer | |
  • "The supertype is very much tied to the layer, in this case, even though it does not underlie everything. I don't think it's wrong to call this a layer superclass." What then is your opinion with regards to my second question? To reiterate, if for example in DDD layer we have class Animal, from which classes Cats and Dogs derive, would you consider Animal as being a Layer Supertype? – EdvRusj Jun 20 '13 at 17:03
  • 1
    Possibly. I suppose I'd also take into consideration how pervasive Animals are in the layer: Are most Domain Objects Animals, or only a small percentage? Do Animals have Teeth and Fur and Movement Strategies and Activity States (awake/asleep/hibernating/dead) and a myriad of other types of classes? If so, I'd probably just see "Animal" as just another superclass. If Everything in the Domain Layer is and Animal, Vegetable, or Mineral, I might be inclined to see those as three Layer Supertypes. So, no hard fast rule. The point is that the supertypes be useful more than anything. – Matthew Flynn Jun 21 '13 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.