Note that there are some explanatory texts on larger screens.

plurals
  1. POAny suitable patterns for this problem?
    primarykey
    data
    text
    <p>I have a situation in which I am attempting to keep my model and implementation as loosely coupled as possible, however I am faced with a situation where the coupling could potentially get a lot closer than I want.</p> <p>I have a selection of 'Model' classes, all implementing interfaces. Additionally I have 'Data Access' classes, which provide a number of functions, one of which is decoding integer lookup values into their full 'object' representation.</p> <p>Within my model classes I want to provide access to these decoded values without requiring the model to know about the data access classes.</p> <p>A simplified example is:</p> <pre><code>/// Core classes -- class Car : ICar { public int MakeId { get {...} set { ... } } public IMakeInfo Make { get {...} } public string Registration { get { ... } set { ... } } public int CurrentOwnerId { get { ... } set { ... } } public IPerson CurrentOwner { get { ... } } } class MakeInfo : IMakeInfo { public string Name { ... } public int Id { ... } public decimal Weight { ... } // etc etc } /// Data Access Classes -- class ResolveMake { public IMakeInfo GetMakeInfo(int id) { // Implementation here... } } </code></pre> <p>How do I enable the <code>Car</code> class to provide the <code>IMakeInfo</code> object to any consuming classes without directly making it aware of the ResolveMake class? In the actual instance I am working with the Car class is not in the same namespace as the ResolveMake class and it contains no references to any instances of it.</p> <p>Some of my options:</p> <ul> <li>Implement a delegate in <code>Car</code> which can be supplied with an instance of the <code>GetMakeInfo</code> method.</li> <li>Some kind of dependency injection</li> <li>Closely couple Car to ResolveMake and be done with it.</li> <li>Any other options?</li> </ul> <p>Any suggestions welcome!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload