![]() |
Home | Articles | Talks | Links | Contact Me | ISA | ThoughtWorks |
A type that acts as the supertype for all types in its layer
Often all the objects in a layer will have some common methods that you don't want to have duplicated throughout the system. So you can move all of this behavior into a common Layer Supertype.
Layer Supertype is a simple idea that leads to a very short pattern. All you need is a superclass for all the objects in a layer. For example all the domain objects in a Domain Model might have a superclass called Domain Object. Common features, such as the storage and handling of Identity Fields can go there. Similarly all Data Mappers in the mapping layer may have a superclass which can rely on the fact that all the domain objects have a common superclass.
If you have more than one kind of object in a layer, then it's useful to have more than one Layer Supertype.
Use Layer Supertype when you have common features from all objects in a layer. Often I do this automatically now, because I so often make use of common features.
Domain objects can have a common superclass for id handling.
class DomainObject... private Long ID; public Long getID() { return ID; } public void setID(Long ID) { Assert.notNull("Cannot set a null ID", ID); this.ID = ID; } public DomainObject(Long ID) { this.ID = ID; } public DomainObject() { }
![]() | ![]() |