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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:59:35+00:00 2026-06-08T12:59:35+00:00

I would like to extract an interface of a class that needs initilization. public

  • 0

I would like to extract an interface of a class that needs initilization.

public class Example<T>
{
    public Example(SomeData data)
    {
        // initialize self with data
    }

    public IEnumerable<T> GetObjects(SomeData data)
    {
        // extract data
    }
}

The problem is that we can’t write an interface that would enforce non-default type constructors. I could of course change my class to:

public interface IExample<T>
{
    void Initilize(SomeData data);
    IEnumerable<T> GetObjects(SomeData data);
}

public class Example<T> : IExample<T>
{
    public void Initilize(SomeData data)
    {
        // initialize self with data
    }

    public IEnumerable<T> GetObjects(SomeData data)
    {
        // extract data
    }
}

But this is not the same, because when one would instantiate this type could directly call into GetObjects which would then result in an exception that instance is not initilized.

What other options do I have?

  • 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-08T12:59:37+00:00Added an answer on June 8, 2026 at 12:59 pm

    As this is just an interface, you shouldn’t care about the constructor. The interface defines what the implementations can do but not specifically how they do it or what order methods are called in.

    How can you realistically say that in the future there won’t be some implementation of the interface that works differently and doesn’t require the constructor?

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

Sidebar

Related Questions

I would like to extract and construct some strings after identifying a substring that
I would like to extract the information that is printed after a git status
I would like to extract the data and event name from a google calendar
I would like to extract UID from /etc/passwd file which looks like this- www-data:x:33:33:www-data:/var/www:/bin/sh
I would like to extract the form data from a PDF using a library,
I would like to extract a color histogram out of a BufferedImage (Java). I
I would like to extract portion of a text using a regular expression. So
I would like to extract items from this sample html, more specificly, i would
I would like to extract the GPS EXIF tag from pictures using php. I'm
I would like to extract a value or its inverse from database. I would

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.