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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:15:13+00:00 2026-06-10T07:15:13+00:00

I’m new to .net and OOP and I’ve been having difficulty working out how

  • 0

I’m new to .net and OOP and I’ve been having difficulty working out how I should create classes for a property site I’m building.

In my database, I have a “House” table with various fields.

Sometimes, a house may have a garden, or garage, a pool etc, so I have separate tables to store the data on each of these, all connected to the “House” table’s unique identifier.

In my code, I have created a “House” class, but how do I then define classes for the other tables?

I could obviously have a “Garden” class, which would inherit the “House” class, but, depending on a visitor’s selections, I may sometimes need to display data on (for example) the house, the garden and the garage and I can’t see how this method would work. I could just have one big class that defines the house, the garden, the garage and so on and leave lots of nulls when something isn’t needed, but I’m pretty sure that can’t be the correct approach!

I’ve been struggling with this all day, so any info is very much appreciated!

  • 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-10T07:15:15+00:00Added an answer on June 10, 2026 at 7:15 am

    House class may have a collection of features.

    You can basicly create an abstract base class called “Feature” or an interface called “IFeature” and inherit/implement it to the class that is meant to be a feature (i.e. Garden).

    Then all you need to do is creating a collection in House class called “Features”.
    Here is an example interface in C#:

    interface IFeature
    {
        // Properties or methods you want all the features to have.
    
        decimal Price { get; }
    }
    

    Your feature classes need to implement IFeature interface.

    class Garden : IFeature
    {
        // This property is needed to implement IFeature interface.
        public decimal Price { get; private set; }
    
        public Garden(decimal price) { Price = price; }
    }
    

    To implement IFeature, a class must have a decimal property called “Price” with a get accessor like the Garden class above and the Pool class below:

    class Pool : IFeature
    {
        public decimal Price { get; private set; }
        public float Depth { get; private set; }
    
        public Pool(decimal price, float depth) { Price = price; Depth = depth; }
    }
    

    House class should have a collection of IFeature instead of Pool or Garden:

    class House
    {
        public List<IFeature> Features { get; private set; }
    
        public House()
        {
            Features = new List<IFeature>();
        }
    }
    

    Then, you can add features to a house like this:

    House h = new House();
    
    h.Features.Add(new Garden(6248.12m));
    h.Features.Add(new Pool(4830.24m, 10.4f));
    

    And using LINQ, you can,

    // Check whether the house has a garden:
    h.Features.Any(f => f is Garden);
    
    // Get the total cost of features.
    h.Features.Sum(f => f.Price);
    
    // Get the pools that are deeper than 5 feet.
    h.Features.OfType<Pool>().Where(p => p.Depth > 5f);
    
    // etc.
    

    More information about interfaces.
    More information about LINQ.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.