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 7755171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:30:06+00:00 2026-06-01T12:30:06+00:00

I’m trying to make an app I’m designing more generic and implement the command

  • 0

I’m trying to make an app I’m designing more generic and implement the command pattern into it to use manager classes to invoke methods exposed by interfaces.

I have several classes with the GetItem() and GetList() methods in them, some are overloaded. They accept different parameters as I was trying to use dependency injection, and they return different types. Here are a couple of examples:

 class DatastoreHelper
    {
        public Datastore GetItem(string DatastoreName)
        {
            // return new Datastore(); from somewhere
        }
        public Datastore GetItem(int DatastoreID)
        {
            // return new Datastore(); from somewhere
        }
        public List<Datastore> GetList()
        {
           // return List<Datastore>(); from somewhere
        }
        public List<Datastore> GetList(HostSystem myHostSystem)
        {
           // return List<Datastore>(); from somewhere
        }

    }
    class HostSystemHelper
    {
        public HostSystem GetItem(int HostSystemID)
        {
          //  return new HostSystem(); from somewhere
        }
        public List<HostSystem> GetList(string ClusterName)
        {
            //return new List<HostSystem>(); from somewhere
        }
    }

I’m trying to figure out if I could use a generic interface for these two methods, and a manager class which would effectively be the controller. Doing this would increase the reuse ability of my manager class.

  interface IGetObjects
    {
        public object GetItem();
        public object GetList();
    }

class GetObjectsManager
{
    private IGetObjects mGetObject;
    public GetObjectsManager(IGetObjects GetObject)
    {
        this.mGetObject = GetObject;
    }
    public object GetItem()
    {
        return this.mGetObject.GetItem();
    }
    public object GetList()
    {
        return this.GetList();
    }
}

I know I’d have to ditch passing in the parameters to the methods themselves and use class properties instead, but I’d lose the dependency injection. I know I’d have to cast the return objects at the calling code into what they’re supposed to be. So my helper classes would then look like this:

class DatastoreHelper
{
    public string DatastoreName { get; set; }
    public string DatastoreID { get; set; }
    public object GetItem()
    {
        // return new Datastore(); from somewhere
    }
    public List<object> GetList()
    {
       // return List<Datastore>(); from somewhere
    }

}
class HostSystemHelper
{
    public int HostSystemID { get; set; }
    public string ClusterName {get; set;}
    public object GetItem()
    {
      //  return new HostSystem(); from somewhere
    }
    public List<object> GetList()
    {
        //return new List<HostSystem>(); from somewhere
    }
}

But is the above a good idea or am I trying to fit a pattern in somewhere it doesn’t belong?

EDIT: I’ve added some more overloaded methods to illustrate that my classes are complex and contain many methods, some overloaded many times according to different input params.

  • 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-06-01T12:30:07+00:00Added an answer on June 1, 2026 at 12:30 pm

    The first code samples look quite similar to the Repository Pattern. I think this is what are you trying to apply. The last sample is not good and Jon told you why. However, instead of reinventing the wheel, read a bit about the Repository (lots of questions about it on SO) because, if I understood correctly, this is what you really want.

    About reuse, not many things and especially persistence interface are reusable. There is the Generic Repository Pattern (I consider it an anti-pattern) which tries to accomplish that but really, do all the application needs the same persistence interface?

    As a general guideline, when you design an object, design it to fullfil the specific application needs, if it happens to be reused that’s a bonus, but that’s not a primary purpose of an object.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.