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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:29:14+00:00 2026-06-16T11:29:14+00:00

I have a class hierarchy that represents a JSON based API. There is a

  • 0

I have a class hierarchy that represents a JSON based API. There is a generic factory that calls and deserializes the api into classes using .NET 4 (no 3rd party libs). I am trying to avoid having to instantiate the class to retrieve a read-only piece of information that is unique to each class.

I had thought (until I started reading this and this, …) I would associate a static URL with a base class/interface and then set it in the derived class’s constructor. Something like (this example will not work):

abstract class url {
  public abstract static string URL; // This is invalid syntax!
}

class b : url {
  static b () { URL = "http://www.example.com/api/x/?y=1"; }
}

class c: url {
  static c () { URL = "http://www.example.com/api/z"; }
}

// ... so the factory can do something like ...
b result = doJSONRequest<b>(b.URL);

This doesn’t work. The static field can’t be abstract, nor can it be uniquely set in b and c as the static variable is stored in the class it is defined in (url in this case).

How can I have a read only item associated with a class such that you can access the item (etc.) without having to instantiate the class?

  • 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-16T11:29:15+00:00Added an answer on June 16, 2026 at 11:29 am

    I’ve implemented a pattern like this to help remind me of constants that I need to setup per derived class that need to be statically accessible:

    public abstract class Foo
    {
        public abstract string Bar { get; }
    }
    
    public class Derived : Foo
    {
        public const string Constant = "value";
        public override string Bar
        {
            get { return Derived.Constant; }
        }
    }
    

    I’ve even found that after implementing this pattern that the polymorphic use of the constant to be just as helpful.

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

Sidebar

Related Questions

I have an hierarchy of classes that looks like the following: class Critical {
Having in mind the abstract factory pattern, imagine that you have a class hierarchy
I have a simple Class Hierarchy that I am trying to get to work
Suppose you have a Java class hierarchy of about 30 classes, with a base
I have a class hierarchy that's three levels deep, like this: class A {
A have a class hierarchy that looks somethign like this: class AbstractDataType { public:
I have a class hierarchy that looks like this: class Base<TElement> { public TElement
I have a C++ class hierarchy that looks something like this: class A; class
I have a class that represents the state of the world. The class has
Suppose I have a composite class PharmaProduct (which represents the product hierarchy of a

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.