In a project at work we have a certain value type class in our domain model that includes a very large number of attributes...
public class BigValueType {
private Foo foo;
private Bar bar;
private Baz baz;
//...
}
We've realized that we would like to "focus" this into a number of different, somewhat more specialized classes that only have some subset of this class's attributes. I think we would like to have something like different "views" of this data.
public class SpecializationA {
private Foo foo;
private Baz baz;
//...
}
public class SpecializationB {
private Bar bar;
private Baz baz;
//...
}
private class SpecializationC {
private Foo foo;
private Bar bar;
//...
}
However, this domain model is intended to be rather general, and not specific to this project. It will have project-specific extensions added to it during future projects, but the common domain model will be kept separate from these extensions. If we simply define a bunch of classes now, it's likely that other projects using the domain model will just have to write their own slightly different ones later. (We can't easily predict what views of this data will be useful.)
I think what we should do is write project-specific Adapters for this big class that present the different views of the data. This way, future users of the domain don't have to touch anything in the "common" domain model to define new views of this information.
public class AdapterA {
private BigValueType wrapped;
//...
public ViewA(BigValueType wrapped) {
//...
}
public Foo getFoo() {
return wrapped.getFoo();
}
//...
}
This makes more sense to me than normal inheritance because our top-level class/interface would have almost nothing in it.
Any feedback on this approach?