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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:14:02+00:00 2026-05-16T01:14:02+00:00

I am trying to decide among three different implementations. I have an IPerson interface,

  • 0

I am trying to decide among three different implementations.

I have an IPerson interface, all people types (ie. police officer, student, lawyer) implement this. Each person type needs to have a different AddressLocation (ie. home, office, mailing). This location never changes so it can be static/readonly. People are handled generically so my save method SavePerson(IPerson person) takes anything that inherits from the IPerson interface and I have a LoadPerson(int ID) method that takes an ID.

My initial solution was to add a DefaultLocation property to IPerson and only have a getter. This way I can use generic methods to save the data. A problem arises when I try to load the data as I do not have an instance of the class yet so I can not reference the property.

On the other hand I can create a public static readonly DefaultLocation property on each of my people types. In this case I can call Student.DefaultLocation and pass that into the method loading my data.

Which way should I go and why? Both appear to have pros and cons.

A third option came to me as I was typing this question:
What if I used a public static readonly proprty which could be referenced without an instantiation of the class and then used a public property without a setter which could be called from the generic methods?

Per Jon’s advice I went with:

public interface IPerson
{
    LocationType DefaultLocation { get; }
}

public class PoliceOfficer : IPerson
{
    public static readonly LocationType _DefaultLocationType = LocationType.Office;
    public LocationType { get { return _DefaultLocationType; } }
}
  • 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-16T01:14:02+00:00Added an answer on May 16, 2026 at 1:14 am

    The last option sounds like the best one to me – at least if you want each type’s location to be available to the rest of the code. If you don’t, I’d just use a private readonly static field in each type, and return that value from the instance property. (I’m assuming locations are immutable.)

    Basically you’re using polymorphism here in a slightly unusual way in that it doesn’t depend on the state of the particular object or any particular behaviour, but the state in terms of the type. Note that by using a property in the interface rather than having an abstract base class with a field set in the constructor, you avoid having one field per instance with basically redundant data.

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

Sidebar

Related Questions

I'm trying to decide whether to switch from having Hibernate sprinkled all over to
I trying to decide whether we went to Flex, Silverlight or even ExtJS. There
I am trying to decide the pros and cons of the 2 ORM primarily
I'm currently trying to decide the merits of encrypting the web.config for a Web
I'm trying to decide how to choose between the WSO2 Gadget Server and WSO2
I'm trying to decide the best way of having radiobuttons switch around the contents
I'm trying to decide whether I should create a simple StackPanel with Buttons on
I'm trying to decide what validation approach to take for a new ASP.NET MVC
I'm currently trying to decide wether to accept a client's proposal or not. Basically,
I am trying to decide on which approach to take in a database I

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.