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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:55:17+00:00 2026-06-06T18:55:17+00:00

I’m about flipped upside down here What I’m trying to do is create a

  • 0

I’m about flipped upside down here

What I’m trying to do is create a bit of a factory that works on different types of tickets. So I’ve create an ITicket interface that has a couple signatures like

GetOpen(); 
GetById(int id);

Now, these methods need to return an instance or a list of instances of the same ticket type, so i thought i’d have the interface look like this

List<ITicket> GetOpen();
ITicket GetById(int id);

So in practice, I hoping to create the factory method like this:

public static List<ITicket> GetOpen(ITicket ticket)
{
   return ticket.GetOpen();
}

Ok, now for example, I went back to my class MocRequest and implemented the List GetOpen() method like this:

public List<MocRequest> GetOpen()
{
   //implementation grabs a bunch of MocTickets out of the database 
   and converts them into instances of the MocTicketClass and returns them
}

I get an error saying this isn’t a valid implementation because the return type is MocRequest instead of ITicket. I thought that MocRequest IS A ITicket at this stage, in hindsight I guess it’s a bit circular so it doesn’t work. The return type needs to be MocRequest so that it can still be used.

I’ve experimented with making the interface into something more like ITicket<T> but then I still have to specify the ticket class type in the factory which kind of defeats the purpose.

So the objective here was to create a single static method in the factory that would handle this stuff. Am I going about this right way? How do I make this work? Or am I still stuck making multiple methods to handle them? TIA

  • 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-06T18:55:19+00:00Added an answer on June 6, 2026 at 6:55 pm

    MocRequest may be an ITicket, but that doesn’t make a List<MocRequest> a List<ITicket>.

    If you return a List<MocRequest> where a List<ITicket> is expected, a user of your API might use the resulting list and add an ITicket that is not a MocRequest. What will the List<MocRequest> do in that case? It will break, right?

    Therefore, the compiler insists on you returning a List<ITicket>.

    In general, it’s not adviseable to return List<T>, because it’s not evident whether you’re returning a copy of something internal or a reference to the actual internal list. Better declare the return type as IEnumerable<ITicket>, which basically means that you just return the tickets, not a writeable list object. (The user of your API is free to insert those tickets into a list of his/her own.)

    For more info on how to return the enumeration, we’ll need to get more information about what the tickets look like after being fetched from the DB. Are they in a list or do you construct that list etc.?

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.