I have one DTO which has only the simple properties on it.
I would like to make some tests on DTO instances let’s say like: IsOld, IsFromBataFamily etc.
I was thinking to extend the DTO class and implement those tester methods.
public class TestableDTO : DTO
{
public bool IsOld() { // some logic }
public bool IsFromBataFamily () { // some logic }
}
Is there any design pattern matching with this approach (Extending a DTO class to add some testers on it to classify its category)?
Can you name it, please?
That’s just plain inheritance, not sure if it has a pattern associated with it. If your
TestableDTOheld aDTOreference internally with the aim of adding members to it, that would be the Decorator pattern, or at least a flavour of it.So the short answer is no, currently this isn’t a “design pattern” per se, but instead an OO paradigm of class inheritance, or extensibility.
Just to clarify, what you have done to add members to the class is perfectly fine. However, the reasons for it (just for testing) might be considered a little odd, as you should just be able to directly test
DTO.