Currently, I have a system with a Data Mapper and multiple Domain Objects which inherit from the same class, let's say B and C that inherit from abstract class A.
In order to retrieve data, I need to pass a parameter to the data interface (getObject('a'), getObject('b')), based on which data for class B or class C will be returned. Then, the Data Mapper uses a Factory class to create the correct object based on some parameters (coming from the data itself).
Class B and class C only differ in the implementation of one method, the rest is inherited from class A.
I have a few doubts on this, it seems flawed but I can't really figure out a better way of doing it. The points are:
- Is inheritance a good way to go about the implementation of different entities that differ in concept but only very slightly?
- Is the factory class a good way to return the correct Domain Object?
- Consuming the data mapper with a parameter feels wrong, is there a better way to do this? Would the use of abstraction be any better?
I hope I have explained it clearly enough, if not I'd be happy to clarify.