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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:30:53+00:00 2026-06-04T16:30:53+00:00

Consider the following class diagram: +——–+ * +————+ | Person |——>| Property | +——–+

  • 0

Consider the following class diagram:

+--------+     * +------------+ 
| Person |------>|   Property |
+--------+       +------------+
                      ^
                      |
             +--------+------+
             |               |
      +----+----+     +------+-----+
      |   Car   |     |   House    |
      +---------+     +------------+

Person has many properties including Car, House, Smartphone etc. Each of these properties has different attributes (Car has an engine size, model, year… House as an address, size, etc).
There are many subclasses (types of properties).

Right now my implementation is having Property an abstract class with a type field. I check the type and cast it to the right subclass by it.

My question is: Is this the only way? is this the right way to do it?
It doesn’t feel so right, so please share your design thoughts with me. A radical change would also be accepted.

  • 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-04T16:30:55+00:00Added an answer on June 4, 2026 at 4:30 pm

    It really depends on how you’d like to use those Propertys, generically or specifically (or both). If the only thing they have in common is the fact that they can be owned, I’d prefer to have a common interface between them, not a common base class. Then, you could store them in a collection and have capability-specific methods that act on subsets of the collection, which would first filter the collection based on the desired capability. Capabilities are more like interfaces and roles than types and classes; so you can have a level of independence between what you want to achieve (your intent) and how you achieve it (your implementation).

    In pseudo-C#-code, it could look like this:

    interface Property {}
    interface Valued {
      Money Value { get; }
    }
    class Person {
      private Collection<Property> properties;
      public Money TotalValue {
        get {
          return properties.OfType<Valued>().Sum(v => v.Value);
        }
      }
    }
    

    You also can filter by specific type, like if you want to do something with all Cars, by using the same technique. A more general method could return all properties of a specific type so that the client can execute some specific logic with them.

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

Sidebar

Related Questions

Consider the following class DialgBean.java, which defines the properties of a dialog box on
Consider the following class definitions: class Person[+T <: Person[T]] class Student() extends Person[Student] class
Consider the following class: public class Score { private static readonly Guid _relationId =
Consider the following class class A{ public void init(){ //do this first; } public
Consider the following class hierarchy: public class Foo { public string Name { get;
Consider the following class public class Class1 { public int A { get; set;
consider the following class: class Order { int OrderId {get; set;} int CustomerId {get;
Consider the following class definition: class StrToTokens { StrToTokens(const char* str, const char* delimiters
Consider the following class definitions: import com.codahale.logula.Logging abstract class A extends Logging { log.info(from
Consider the following code: class A { private $a; function f() { A::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.