Inherit members from multiple classes

I studied design with OOD and stuck with the script.

I have a class Userthat extends an abstract class Person. The class Personhas a member with a type Address. Useronly have a username and password, and Addresssome string fields.

Now I want to add a class Clientthat can be Personor Organization(will be added). Clientwill also have some data.

I was thinking about interfaces, but they can only have methods. Can someone help me with what will be the right design?

I do not follow any pattern and coding with C # .NET.


Update

I think I could not explain the script properly. Sorry for that. Please look at the chart. Here the class Clientis what I want to add. Incomplete class diagram of my scenario

+4
source share
1 answer

Try working with a composition. The person and organization are not necessarily users, although both may have an address or user account. In fact, they most likely have more than one of them. If you think more in terms of HAS A and less in terms of IS A, you can come up with more convenient options. For example, you may have

class Address {
  public string street {get; private set;}
  public string city {get; private set;}
  public AddressTypes AddressType {get; private set;} // an enum to differentiate 
                                                      // "home address", "legal address"
  ...
}

now if you need to simulate the fact that both Personare and Organizationare things that Addresses should have , you can create an interface

interface IAddressable {
   IEnumerable<Address> {get;}
}

Person Organization . Account, Username Password.

Person Organization BE User s, , , . , .

Client, . , " ( ) ". " ", Person .

, Person . , , , - , ( , ). , :

abstract class Client : IAddressable, IWithAccount {
   // implement IAddressable and IWithAccount
}

class PersonClient : Client
{
    public PersonClient(Person person)
    {
        // make the Client address refer to the Person address
        // make the Client account refer to the Person account
    }
}

class OrganizationClient : Client
{
    public OrganizationClient(Organization organization)
    {
        // make the Client address refer to the Organization address
        // make the Client account refer to the Organization account
    }
}

:

  • , - () (Person, Organization).
  • , , , StateClient
+3

All Articles