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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:29:15+00:00 2026-06-03T09:29:15+00:00

I have a Person base class and three derivatives. On the edit page I

  • 0

I have a Person base class and three derivatives. On the edit page I have a section with general person data (name, address, etc.).

I also want a section per subclass. So if a Person is a User I want to add a section with the specific user data. If a Person is also a CardHolder I want to show the card holder section.

I am struggling on how to implement this. What I have in mind is to ask the UserRepository if the specified Person is a User. If so, the method will return a User object; otherwise null. I am planning to do this for all the subclasses.

However, I have this feeling that this can be done a better way, but I can’t find that way.

EDIT:
I have the following scenario. I have an overview with Person objects (not the derivatives!). When a row is clicked, I want to show the details page. On this page I have the different sections as described above. At this point I want to know if the ‘Person’ is also a User or a ‘Cardholder’.

I’d like to apply polymorphism, but I don’t see how…

  • 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-03T09:29:17+00:00Added an answer on June 3, 2026 at 9:29 am

    Have an abstract function on the Person class called something like “ReturnValidSectionsForPerson()“. In each subclass, override that function to return “UserData” or “CardHolder” as appropriate. You can use an enumeration to hold the various types of sections to make it easier to read and maintain.

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

Sidebar

Related Questions

the question is simple. I have a base abstract class (person). From this i
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have a model in my rails application which is class Person < ActiveRecord::Base
I have a Person class. A person class contains a collection of Friends (also
I have an abstract base class Contact that has two subclasses: Person and Company
I have a three classes: First is Person: public class Person { public string
I have a base class Person and derived classes Manager and Employee . Now,
i have some data to write in data base (three strings); i have a
I have class Person class person{ int ID ; sting FirstName ; string Last
I have a Person Class and based on some help I received in this

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.