0

I'm confused on how to best use this pattern. I have a project that uses Devart's Entity Framework for Oracle. The context is provided by them. So I have an interface IRepository and a single concrete implementation OracleRepository that has a private reference to the context.

Now to my question. Do the model class definitions in this case EntityObjects all need to be abstracted out as well? I'm thinking the client class must be able to resolve the return types to access the properties of the EntityObjects but both contexts would need to have access to the same class definitions. Do I need to make an interface for each object type from the model?

The motivation is to allow different ORM and data storage options in the future.

The example provided here

Course course = unitOfWork.CourseRepository.GetByID(id);

The client must know what Course is essentially. Should that be ICourse instead?

  • Personally I think an interface for each POCO/POJO is overkill - your domain objects don't do work, they represent data – Liath Mar 29 '18 at 14:52
  • Why are you concerned about the client having access to the data classes? They represent data, and your client will need to interact with the data. You can certainly make an ICourse interface, but do you actually have multiple implementations of Course that would use it? Presumably all implementations will have the same properties, and since they store data, not logic, they'll end up looking exactly the same. – Kris Harper Mar 29 '18 at 15:45
  • @KrisHarper in order to have two different contexts referencing two data stores for the same type of data, wouldn't I need to have multiple implementations of Course? – Felix Castor Mar 29 '18 at 20:42
  • How are they different though? Presumably they each have one property per database column and foreign key relationship, and no logic since they are data stores. So if they have the same set of properties, with the same names, and no methods (or just basic ones like ToString) then the classes are identical, no? – Kris Harper Mar 30 '18 at 2:25
  • @KrisHarper ah I see what you are saying. I think I'm getting screwed up in using Database first design. The model is automatically generated for me, EntityObjects. So a POCO may fix this? – Felix Castor Mar 30 '18 at 13:28

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.