I have an error which says 'House' does not contain a definition for 'Display'

Algorithme T

Member
Joined
Sep 26, 2022
Messages
15
Programming Experience
Beginner
I initialy created my class which contained constructors and method
Each of them has been saved in different files found in different folders , now the methods are in the Services folder and the constructors in Models folder


personService:
using HouseMS.Models;

namespace HouseMS.Services
{
    internal class PersonServices : Person
    {
        public void Display()
        {
            Console.WriteLine("Je m'appele {0}.", name);
            house.Display();
            house.Door.Display();
        }
    }
}

Person class found in Models:
using HouseMS.Services;

namespace HouseMS.Models
{
    internal class Person
    {
        protected string name;
        protected House house;
        public Person()
        {
            name = "Jonas";
            house = new House(4);
        }
        public Person(string name, House house)
        {
            Name = name;
            House = house;
        }
        public string Name { get; set; }
        public House House { get; set; }
       
    }
 
Last edited by a moderator:
And does this House class have a Display method? Presumably not. Why do you think it does? You haven't shown us any House type and the only Display method is in the PersonServices class, so I'm not sure what you want us to do.
 
Don't do this:

C#:
        protected House house;

...

        public House House { get; set; }

Having members that differ only by case is a recipe for confusion, and not fully compatible with every syntax in the .net ecosystem - some syntaxes (such as VB) are not case sensitive
 
And does this House class have a Display method? Presumably not. Why do you think it does? You haven't shown us any House type and the only Display method is in the PersonServices class, so I'm not sure what you want us to do.
My display method is found in HouseService but i do not know how to get this done because HomeService inherites Home but there's no way Home inherites from HomeService
 
Inorder to be clear
My aim is to make it possible for my ApartmentService to use the attribute "surface" found in class House which is inherited by class Apartment

ApartmentService

ApartmentService:
using HouseMS.Models;

namespace HouseMS.Services
{
    internal class ApartmentService:HouseServices
    {
        public override void Display()
        {
            Console.WriteLine("Je suis un appartement, ma surface est " + surface + " m2");
        }
    }
}

Apartment:
using HouseMS.Services;

namespace HouseMS.Models
{
    internal class Apartment : House
    {
        public Apartment() : base(50)
        {
        }
    }
}

House class:
namespace HouseMS.Models
{
    internal  class House
    {
        public int surface { get; set; }
        public Door door { get; set; }
        public House(int surface)
        {
            this.surface = surface;
            door = new Door();
        }

        
    }
}
 
You also need to show us the code for HouseServices since ApartmentServices inherits from that class.
 
You also need to show us the code for HouseServices since ApartmentServices inherits from that class.
HouseService:
using System.Threading.Tasks;

namespace HouseMS.Services
{
    internal class HouseServices
    {
        public virtual void Display()
        {
            Console.WriteLine("Je suis une maison, ma surface est de {0} m2.", surface);
        }
    }
}
 
Well, it looks like your HouseServices also has the same problem where it can't access surface. Your class House exposes a surface property. You need an instance of a house so that you can access read the value from that instance.

Right now, you have something like a postal service and within the postal service, you are trying to get the address. But you need a piece of mail to be looking at read the address from it. You currently don't have that piece of mail.

My gut feel is that you have the incorrect infrastructure. Typically with modern architectures, model objects represent real world objects, while services represent operations on those objects or access to repositories of those objects.

Based on your original post where you are trying to make PersonServices inherit from Person, you are going down the old fashioned data cursor architecture that Borland and a few other companies tried. It was relatively good for the systems back then when computers had very limited memory and everyone and their brother wanted to write a dBase-like program where people were just going forwards and backwards through records, and people were writing procedural code. With the advent of object oriented programming, typically, these cursor style operations are now encapsulated by an iterator or enumerator design pattern.
 
Last edited:
Well, it looks like your HouseServices also has the same problem where it can't access surface. Your class House exposes a surface property. You need an instance of a house so that you can access read the value from that instance.

Right now, you have something like a postal service and within the postal service, you are trying to get the address. But you need a piece of mail to be looking at read the address from it. You currently don't have that piece of mail.
not sure i know what to do here
 
Well, it looks like your HouseServices also has the same problem where it can't access surface. Your class House exposes a surface property. You need an instance of a house so that you can access read the value from that instance.

Right now, you have something like a postal service and within the postal service, you are trying to get the address. But you need a piece of mail to be looking at read the address from it. You currently don't have that piece of mail.

My gut feel is that you have the incorrect infrastructure. Typically with modern architectures, model objects represent real world objects, while services represent operations on those objects or access to repositories of those objects.

Based on your original post where you are trying to make PersonServices inherit from Person, you are going down the old fashioned data cursor architecture that Borland and a few other companies tried. It was relatively good for the systems back then when computers had very limited memory and everyone and their brother wanted to write a dBase-like program where people were just going forwards and backwards through records, and people were writing procedural code. With the advent of object oriented programming, typically, these cursor style operations are now encapsulated by an iterator or enumerator design pattern.
OK .. i have removed every of those inheritance
but doesn't solve my pb
 
I told you how to solve the problem:
You need an instance of a house so that you can access read the value from that instance.

An alternative is simply put the Display() method on the House class instead of the HouseServices class, and get rid of all your services classes.
 
Can you describe in words the infrastructure you're trying to create? An artificial example using code that doesn't work, with no accompanying explanation of what one is trying to achieve overall (i.e. "I'm trying to create a sytem that does.." not "i'm trying to call the display method of the house object") is fairly hard to decipher
 
Back
Top Bottom