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

  • SEARCH
  • Home
  • 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 5843325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:08:20+00:00 2026-05-22T12:08:20+00:00

Below are three implementation of the interface. The only difference between implementation 1 and

  • 0

Below are three implementation of the interface. The only difference between implementation 1 and implementation 2 is the namespace containing the ItemWrapper. Can this be refactored using generalization or something else perhaps?

interface IItemProvider {
    object GetItem(Item item);
}

//1
class SomeNamespaceProvider : IItemProvider {
    object GetItem(Item item) {
        return SomeNamespace.ItemWrapper.GetItem(item);
    }
}

//2
class OtherNamespaceProvider : IItemProvider {
    object GetItem(Item item) {
        return OtherNamespace.ItemWrapper.GetItem(item);
    }
}

//3
class TotallyDifferentProvider : IItemProvider {
    object GetItem(Item item) {
        return DifferentItemRetriever(item);
    }
}
  • 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-22T12:08:21+00:00Added an answer on May 22, 2026 at 12:08 pm

    From your description I understand that you have static methods in classes SomeNamespace.ItemWrapper and OtherNamespace.ItemWrapper and they don’t implement IItemProvider interface. You want to turn those static methods to instance methods and you don’t know how to do it.

    If classes SomeNamespace.ItemWrapper and OtherNamespace.ItemWrapper aren’t static you could implement IItemProvider explicitly:

    namespace SomeNamespace
    {
        public class ItemWrapper: IItemProvider
        {
            public static object GetItem(TaskRunProcessor.Test.Item item)
            {
                return null;
            }
    
            object IItemProvider.GetItem(Item item)
            {
                return ItemWrapper.GetItem(item);
            }
        }
    }
    

    If they have to stay static or for any reason you don’t have access to the code I would recommend some functional approach:

    public class GenericProvider : IItemProvider
    {
        private Func<Item, object> m_Retriever;
    
        public GenericProvider(Func<Item,object> retriever)
        {
            if (retriever == null) throw new ArgumentNullException("retriever");
            m_Retriever = retriever;
        }
        object GetItem(Item item)
        {
            return m_Retriever(item);
        }
    }
    

    Then you sould be able to use `GenericItemProvider’ like that:

    public class ItemProvderClient
    {
        public void Use()
        {
            IItemProvider provider1 = new GenericProvider(SomeNamespace.ItemWrapper.GetItem);
            IItemProvider provider2 = new GenericProvider(OtherNamespace.ItemWrapper.GetItem);
    
            provider1.GetItem(null);
            provider2.GetItem(null);
        }
    }
    

    In both solution there is no need to create more classes for evey namespace like SomeNamespaceProvider class you had in the firs place.

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

Sidebar

Related Questions

I have a RESTful service with the interface below, using POST. When I try
Please find below my code. Employee class implements IEmployee interface. namespace MiddleWare.ServiceContracts { [ServiceContract(Namespace
Of the below three functions: getc getchar & scanf which is the best one
What is a good way to give the input field below the three characteristics
I know that technically all three ways below are valid, but is there any
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
The code below is checking performance of three different ways to do same solution.
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
It's my understanding that all three of these lines below should return an ARRAY
I have three tables tag , page , pagetag With the data below page

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.