0

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:

  1. Is inheritance a good way to go about the implementation of different entities that differ in concept but only very slightly?
  2. Is the factory class a good way to return the correct Domain Object?
  3. 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.

  • couldn´t you just have juts one class where you have a method that executes and returns the correct method based on those fields in the data itself, if its the only difference !? – john Smith Feb 24 '14 at 22:17
  • But that's the difference because the parameter is different: if the parameter is 'b' data of type B is retrieved, and Object B is created, if 'c' data of type C is retrieved and Object C created. Technically I could create a different object based on the passed parameter and not based on the data... – milo5b Feb 24 '14 at 22:23

Your Answer

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

Browse other questions tagged or ask your own question.