Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 252399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:40:29+00:00 2026-05-11T21:40:29+00:00

I have a situation in which I am attempting to keep my model and

  • 0

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.

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.

Within my model classes I want to provide access to these decoded values without requiring the model to know about the data access classes.

A simplified example is:

/// 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...
    }

}

How do I enable the Car class to provide the IMakeInfo 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.

Some of my options:

  • Implement a delegate in Car which can be supplied with an instance of the GetMakeInfo method.
  • Some kind of dependency injection
  • Closely couple Car to ResolveMake and be done with it.
  • Any other options?

Any suggestions welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:40:30+00:00Added an answer on May 11, 2026 at 9:40 pm

    Extension Methods?

    namespace CarStuff
    {
       class Car : ICar
       {
          public int MakeId { get {...} set { ... } }
          // no Make property...
          public string Registration { get { ... } set { ... } }
          public int CurrentOwnerId { get { ... } set { ... } }
          public IPerson CurrentOwner { get { ... } }
       }
    }
    
    
    namespace MakeExts
    {
       class ResolveMake
       {
          public static IMakeInfo Make(this Car myCar)
          {
             //implementation here
          }
       }
    }
    

    elsewhere:

    using MakeExts;
    
    Car c = new Car();
    Console.WriteLine(c.Make().ToString());
    

    Edit: For using Extension Methods in .NET 2.0, you need something like:

    • http://kohari.org/2008/04/04/extension-methods-in-net-20/
    • http://www.danielmoth.com/Blog/2007/05/using-extension-methods-in-fx-20.html

    Basically, a class containing:

    namespace System.Runtime.CompilerServices 
    { 
       class ExtensionAttribute : Attribute
       {
       }
     }
    

    and a “using System.Runtime.CompilerServices” scattered in relevant places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.