I have a load of object classes in a DLL. These objects are things like People, Addresses, Email Addresses, Telephone Numbers, etc. Each one is represented by a class, and each class has one or more interfaces to interact with other objects. All the interfaces are in a separate DLL.
I have a third DLL whose purpose is to serve as the data access layer and interact between these objects and the database.
When I need to create an object, the object's constructor might call methods from the DAL to populate unknown fields within the object. For example, the Person object might have an Id in the constructor and immediately calls methods from the DAL to get the person's address and telephone number from the database. When this happens, I pass the interface reference to the person object into the DAL method as an argument. It should then do what it has to do and fill missing information for the person.
However, some of these pieces of missing information are stored in other objects - for example, Address, ContactNumber, which are properties and fields of the Person object. These objects cannot be created in the DAL due to their protection level. I don't want to make them public classes as I don't want them to be, and I don't think they need to be.
So my question is, what is the workaround to this? Ideally I don't want any reference from the DAL to the Objects DLL - I want the mutual ground to be the interface DLL. Is this the correct way to go about things?
If it is, I'm therefore assuming the method to initialize objects from the DAL is to have another DLL which pure function is to initialize objects in the objects DLL.
Am i over-complicating things?
The whole reason I separated objects from DAL into two DLL's was so that I could swap DAL for different data structures. I'm not sure whether it's common practice to add a reference from DAL to the objects DLL. Or whether it's necessary. But if it is, and it is necessary, it seems to me to defeat the object of interfaces.
Could anyone shed any light on this? I've put max points on as I've spent all week thinking and researching what to do with this!
Start Free Trial