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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:17:30+00:00 2026-05-16T15:17:30+00:00

C# .Net 4.0 I’d like to know how I can have a class which

  • 0

C# .Net 4.0

I’d like to know how I can have a class which can only be instantiated from one single place. An example:

I’ve got a Provider class. This class exposes a method called GetData. When GetData is called, the Provider will instanciate a Data class, populate and return it. The Data class cannot be instanciated by anybody different then the Provider, so the only way to access the data will be through the Provider. Once GetData is called and a caller has received the Data class instance, he should be able to access properties/methods of this class.

How can this be done? Is there a pattern for this sort of problem? A short sample would be highly appreciated. Thanks in advance!

  • 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-16T15:17:31+00:00Added an answer on May 16, 2026 at 3:17 pm

    It sounds like you are looking for the factory pattern:

    The factory pattern is a creational
    design pattern used in software
    development to encapsulate the
    processes involved in the creation of
    objects.

    Basically your Provider class is the factory that controlls the creation of instances of the Data class.

    One thing you could do control this would be to place these two types in their own assembly and make the constructor for Data be internal but the class itself public. This would mean that anyone who references the assembly would be forced to use the Provider class to create instances of Data (unless they used reflection, of course).

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

Sidebar

Related Questions

net webforms application which is a new version of an old webshop. I have
net ajax app. I have one modelpopup that shows a IFrame and inside Iframe
.Net Compact Framework Scenario: User is on a screen. Device can't finds a printer
.NET newbie here... I'd like to make a button in a Windows form that
.NET 3.5, C# I have a web app with a search feature. Some of
I have a jquery bug and I've been looking for hours now, I can't
.net class SynchronizedReadOnlyCollection has 4 constructors. public SynchronizedReadOnlyCollection(); public SynchronizedReadOnlyCollection(object syncRoot); public SynchronizedReadOnlyCollection(object syncRoot,
.NET Framework: 2.0 Preferred Language: C# I am new to TDD (Test Driven Development).
.NET, Java and other high level database API's in various language often provide techniques
.NET developers out there! Need your opinion here! I am now using Visual Assist

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.