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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:20+00:00 2026-06-02T03:11:20+00:00

I need to over override a property from a List class. My class for

  • 0

I need to over override a property from a List class. My class for example is setup as follows:

    public class Customer
    {
        private int _ID;
        private string _CustomerName;
        private List<CustomerAddress> _CustomerAddressList;

        public int ID { get { return _ID; } set { _ID = value; } }
        public string CustomerName
        {
            get { return _CustomerName; }
            set { _CustomerName = value; }
        }
        public List<CustomerAddress> CustomerAddressList
        {
            get { return _CustomerAddressList; }
            set { _CustomerAddressList = value; }
        }
    }

    public class CustomerAddress
    {
        private string _Address1;
        private string _TelephoneNumber;

        public string Address1
        {
            get { return _Address1; }
            set { _Address1 = value; }
        }

        public virtual string TelephoneNumber
        {
            get { return _TelephoneNumber; }
            set { _TelephoneNumber = value; }
        }
    }

Now I have my Business Layer class which inherits the customer class.

I can override the properities of the customer class, but i can’t work out how to override the properties of the CustomerAddress class in my CustomerBL class? I don’t want to override the List setting but to override the individual properties on each item in the list.

  • 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-02T03:11:22+00:00Added an answer on June 2, 2026 at 3:11 am

    According to the original design, there are only awful solutions:

        public class Customer
        {
            protected List<CustomerAddress> _customerAddresList 
               = new List<CustomerAddress>();
        }
    
        public class Worker : Customer
        {
    
        }
    
        public class CustomerAddress
        {
            protected string _Address1;
            public virtual string Address1
            {
                get { return "customer address: " + _Address1; }
                set { _Address1 = value; }
            }
        }
    
        public class WorkerAddress: CustomerAddress
        {
            public override string Address1
            {
                get { return "Worker Address: " + _Address1; }
            }
        }
    

    If the entity instances are inherited, we have this:

        // Inheriting instances
    
        public class CustomerBL : Customer
        {
            public void AddAdress(CustomerAddress address)
            {
                _customerAddresList.Add(address);
            }
        }
    
        public class WorkerBL: Worker
        {
            // Not inehritable, different signature
            public void AddAdress(WorkerAddress address)
            {
                _customerAddresList.Add(address);
            }
        }
    

    If we inherit the BL classes, we have this:

        // Inheriting BL
        public class CustomerBL2 : Customer
        {
            public virtual void AddAdress(CustomerAddress address)
            {
                _customerAddresList.Add(address);
            }
        }
    
        public class WorkerBL2 : CustomerBL2
        {
            public override void AddAdress(CustomerAddress address)
            {
                if (!(address is WorkerAddress))
                    throw new Exception();
                base.AddAdress(address);
            }
        }
    

    If we use Generics, we have this

        // Using generics
        public class Generic<TAddress>
        {
            private List<TAddress> _addresList
                = new List<TAddress>();
            protected virtual List<TAddress> AddresList
            {
                get { return _addresList; }
            }
        }
    
        public class CustomerG : Generic<CustomerAddress>
        {
        }
    
        public class WorkerG : Generic<WorkerAddress>
        {
    
        }
    

    The problem, no doubt, is that there are two different inheritance chains:

    • one of entities
    • another of BL classes

    And it’s not possible to have a good decision on which is the rigth waty to do it (in fact, I think, with this design there’s no way of doing it right).

    It’s much better to have entities and BL classes independent of each other, so that you can keep both inheritance chains independent, and decide what can and should be inherited in its chain.

        public class Address
        {
        }
    

    Entities can inherit for each other. All right, typical case:

        public class Person
        {
            public List<Address> Adresses;
        }
    
        public class Worker: Person
        {
            // inherits adresses
        }
    

    Inheriting BL Classes (dont’ like it):

        public class PersonBl
        {
            // Functionality which is common fot all the inheritance chain
            public void PrintAdresses(Person person)
            {
            }
    
            // Functionality that can be specialized for each inherited entity
            public virtual void SaveAdresses(Person person)
            {
                // they're are treated differently in each case
            }
    
            // Functionality specific of person
            public void DoSomethingWithPerson(Person person)
            {
                // TODO
            }
        }
    
        public class WorkerBl : PersonBl
        {
            // Uses PersonBl PrintAdresses
    
            public override void SaveAdresses(Person person)
            {
                // do it for worker
            }
    
            // Functionality specific of Worker
            public void DoSomethingWithWorker(Worker worker)
            {
                // TODO
            }
        }
    

    “BL classes using other BL classes” (that’s the way I like it):

        public class Person2Bl
        {
            // Functionality which is common for all the inheritance chain of entities
            public void PrintAdresses(Person person)
            {
            }
    
            public void SaveAdresses(Person person)
            {
               // specific for person
            }
    
            // Functionality specific of person
            public void DoSomethingWithPerson(Person person)
            {
            }
        }
    
    
        // doesn't inherit:
    
        public class Worker2Bl
        {
            // Use the logic in PersonBl2
            public void PrintAdresses(Worker worker)
            {
                // Really not necessary -> this could be done directly in the app code
                Person2Bl bl = new Person2Bl();
                bl.PrintAdresses(worker);
            }
    
            public void SaveAdresses(Worker worker)
            {
               // specific of Worker
            }
    
            public void DoSomethingWithWorker(Worker worker)
            {
                // specific of worker
            }
        }
    

    In fact, it would be better to have an AddressBl that can be used by both WorkerBl2 and PersonBl2

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

Sidebar

Related Questions

Over time I found the need to override several stdlib methods from Python in
I need to iterate over a recordset from a stored procedure and execute another
I need to loop over a query exactly 12 times to complete rows in
I have a 3D array in Python and I need to iterate over all
I have defined a custom struct which I need to send over to another
We need to place text over objects in a web page, similar to this:
I need to write the expression meaning optimize over the parameter set . I
I need to draw a transparent plane over a User control in my DotNET
I need a reliable messaging framework that runs over http/https (due to client security
I need to do a linear interpolation over time between two values on an

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.