Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Could there be a base class for customers, employees and suppliers?

Could there be a base class for customers, employees and suppliers?

Scheduled Pinned Locked Moved Design and Architecture
helpquestion
28 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N nstk

    In a software for a company, we usually have customers, employees and suppliers in what regards humans. Therefore a reasonable (meaning a good one) OOP approach would be to have a class 'Persons' with attributes such as name, surname, address etc. and then let the classes 'Customers', 'Employees' and 'Suppliers' derive from the class 'Persons'. But, on a second thought there is a problem. How do we deal with customers and suppliers which are companies?

    N Offline
    N Offline
    Nagy Vilmos
    wrote on last edited by
    #7

    A reasonable exercise at this point would be to identify the characteristics that you wish to associate with each of the different types. You may well find that there is an hierarchy that you have missed. From experience, there should be a Person that is used to represent a physical being [and maybe a role in some cases] and an Organisation to represent companies [which will have Person contacts. Customer is abstract, as it can be a Person or an Organisation, and will also reference the list of Addresses. For your problem domain, these might not all be needed, but they are a good starting point. You need to analyse how you will be using them, before you can decide how they will be used.


    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

    N 1 Reply Last reply
    0
    • N Nagy Vilmos

      A reasonable exercise at this point would be to identify the characteristics that you wish to associate with each of the different types. You may well find that there is an hierarchy that you have missed. From experience, there should be a Person that is used to represent a physical being [and maybe a role in some cases] and an Organisation to represent companies [which will have Person contacts. Customer is abstract, as it can be a Person or an Organisation, and will also reference the list of Addresses. For your problem domain, these might not all be needed, but they are a good starting point. You need to analyse how you will be using them, before you can decide how they will be used.


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      N Offline
      N Offline
      nstk
      wrote on last edited by
      #8

      Nagy Vilmos wrote:

      From experience, there should be a Person that is used to represent a physical being [and maybe a role in some cases] and an Organisation to represent companies [which will have Person contacts.

      Do you mean in a form of nested classes?

      L N 2 Replies Last reply
      0
      • N nstk

        Nagy Vilmos wrote:

        From experience, there should be a Person that is used to represent a physical being [and maybe a role in some cases] and an Organisation to represent companies [which will have Person contacts.

        Do you mean in a form of nested classes?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #9

        nstk wrote:

        Do you mean in a form of nested classes?

        You are looking at this problem from the wrong direction; forget about the types of classes you need. First define what the problem is and what general process is needed to solve it. Then define the users (people, organisations etc) and what properties they may need. From that information you can start to think about the different classes that will work together to solve the business problem. They may or may not be based on a single base class, but that is not a primary consideration.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        N 1 Reply Last reply
        0
        • L Lost User

          nstk wrote:

          Do you mean in a form of nested classes?

          You are looking at this problem from the wrong direction; forget about the types of classes you need. First define what the problem is and what general process is needed to solve it. Then define the users (people, organisations etc) and what properties they may need. From that information you can start to think about the different classes that will work together to solve the business problem. They may or may not be based on a single base class, but that is not a primary consideration.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          N Offline
          N Offline
          nstk
          wrote on last edited by
          #10

          I understand what you are saying but there is no real project. What I am really trying to do, is to find out why and where to use a base class in a hypothetical (but indeed very common) design problematic of, let's say, an ERP software. If we narrow the problem to customers and employees, and assuming that customers are only individuals, it is obvious that both are persons, therefore a base class Persons and two inherited classes of Customers and Employees seems to be very reasonable. But do we need to build a base class in our programme and if yes why? What is the real practical purpose of doing so? In my opinion this generalization of our two "real" classes seems to complicate designing without any having any profit from it. That is my real question to the forum (although some of the answers above have already answered that too).

          L J 2 Replies Last reply
          0
          • N nstk

            I understand what you are saying but there is no real project. What I am really trying to do, is to find out why and where to use a base class in a hypothetical (but indeed very common) design problematic of, let's say, an ERP software. If we narrow the problem to customers and employees, and assuming that customers are only individuals, it is obvious that both are persons, therefore a base class Persons and two inherited classes of Customers and Employees seems to be very reasonable. But do we need to build a base class in our programme and if yes why? What is the real practical purpose of doing so? In my opinion this generalization of our two "real" classes seems to complicate designing without any having any profit from it. That is my real question to the forum (although some of the answers above have already answered that too).

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #11

            Sorry but you are asking for a tutorial on OOP; take a look at some of these links[^] which should help you.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            N 1 Reply Last reply
            0
            • L Lost User

              Sorry but you are asking for a tutorial on OOP; take a look at some of these links[^] which should help you.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              N Offline
              N Offline
              nstk
              wrote on last edited by
              #12

              Richard MacCutchan wrote:

              Sorry but you are asking for a tutorial on OOP

              Well, not really. I 've read already many books about OOP, even studied and done some programmes. I found out that there can be solutions and concepts which vary a lot. In the above example there could be two solutions with or without inheritance between the classes I mentioned. And both could be acceptable and good. Both? Maybe? THat's why I asked here, to get answers from more experienced members. This cannot be done in a tutorial. Thanks for the links.

              N 1 Reply Last reply
              0
              • N nstk

                In a software for a company, we usually have customers, employees and suppliers in what regards humans. Therefore a reasonable (meaning a good one) OOP approach would be to have a class 'Persons' with attributes such as name, surname, address etc. and then let the classes 'Customers', 'Employees' and 'Suppliers' derive from the class 'Persons'. But, on a second thought there is a problem. How do we deal with customers and suppliers which are companies?

                R Offline
                R Offline
                RobCroll
                wrote on last edited by
                #13

                Add a class called Company and then add an optional CompanyId (can be null) field to the Person class. That way you can deal with individuals and or individuals from a company.

                "You get that on the big jobs."

                N 1 Reply Last reply
                0
                • R RobCroll

                  Add a class called Company and then add an optional CompanyId (can be null) field to the Person class. That way you can deal with individuals and or individuals from a company.

                  "You get that on the big jobs."

                  N Offline
                  N Offline
                  Nagy Vilmos
                  wrote on last edited by
                  #14

                  I'd argue the other way around. Company is not an attribute of a person, but a person - as in a contact - is an attribute of a company.


                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                  R R 2 Replies Last reply
                  0
                  • N nstk

                    Richard MacCutchan wrote:

                    Sorry but you are asking for a tutorial on OOP

                    Well, not really. I 've read already many books about OOP, even studied and done some programmes. I found out that there can be solutions and concepts which vary a lot. In the above example there could be two solutions with or without inheritance between the classes I mentioned. And both could be acceptable and good. Both? Maybe? THat's why I asked here, to get answers from more experienced members. This cannot be done in a tutorial. Thanks for the links.

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #15

                    If you want a good insight into design, try The Gang of Four[^], it provides some very good non-language specific information. If you are serious about design, I would suggest it as a must-have.


                    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                    1 Reply Last reply
                    0
                    • N nstk

                      Nagy Vilmos wrote:

                      From experience, there should be a Person that is used to represent a physical being [and maybe a role in some cases] and an Organisation to represent companies [which will have Person contacts.

                      Do you mean in a form of nested classes?

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #16

                      No. I mean as candidate classes. Begin by writing out in plain English [other languages are available] what you want to do. As an example, your system could be described thus:

                      Requirements:

                      Provide software to manage the relationships between the company and it's suppliers and customers. All the contacts can be either individual people or companies. Any company will have one or more contact. Orders are recieved from customers and placed with suppliers for the provision of Widgets and associated products. Every order received will result in an invoice being raised by the accounting system. Orders placed with suppliers will be filled and invoices for payment will be sent to the accounting system. Each order [inbound or outbound] will have a billing address and a delivery address, these need not be the same. Each customer can have default addresses associated with it.

                      From this initial requirement, you can take out all the nouns and noun phrases. These are your candidate classes. The next stage is to decide which ones are classes in their own right and which are attributes. Often a lot of candidates can be reduced. As an exercise, I would recommend giving this a go and see where it takes you.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      N 1 Reply Last reply
                      0
                      • N Nagy Vilmos

                        I'd argue the other way around. Company is not an attribute of a person, but a person - as in a contact - is an attribute of a company.


                        Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                        R Offline
                        R Offline
                        R Giskard Reventlov
                        wrote on last edited by
                        #17

                        Agreed: start with the largest discreet object and work back from that.

                        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                        1 Reply Last reply
                        0
                        • N nstk

                          I understand what you are saying but there is no real project. What I am really trying to do, is to find out why and where to use a base class in a hypothetical (but indeed very common) design problematic of, let's say, an ERP software. If we narrow the problem to customers and employees, and assuming that customers are only individuals, it is obvious that both are persons, therefore a base class Persons and two inherited classes of Customers and Employees seems to be very reasonable. But do we need to build a base class in our programme and if yes why? What is the real practical purpose of doing so? In my opinion this generalization of our two "real" classes seems to complicate designing without any having any profit from it. That is my real question to the forum (although some of the answers above have already answered that too).

                          J Offline
                          J Offline
                          jschell
                          wrote on last edited by
                          #18

                          nstk wrote:

                          What I am really trying to do, is to find out why and where to use a base class in a hypothetical (but indeed very common) design problematic of, let's say, an ERP software.

                          Again...you start with the problem domain and it defines the classes. If you don't have a problem domain then you cannot defined classes.

                          nstk wrote:

                          But do we need to build a base class in our programme and if yes why?

                          Because the problem domain has requirements that specify that sort of implementation. Or because the problem domain lead to a specific implmentation and that implementation is best implemented that way.

                          1 Reply Last reply
                          0
                          • N Nagy Vilmos

                            No. I mean as candidate classes. Begin by writing out in plain English [other languages are available] what you want to do. As an example, your system could be described thus:

                            Requirements:

                            Provide software to manage the relationships between the company and it's suppliers and customers. All the contacts can be either individual people or companies. Any company will have one or more contact. Orders are recieved from customers and placed with suppliers for the provision of Widgets and associated products. Every order received will result in an invoice being raised by the accounting system. Orders placed with suppliers will be filled and invoices for payment will be sent to the accounting system. Each order [inbound or outbound] will have a billing address and a delivery address, these need not be the same. Each customer can have default addresses associated with it.

                            From this initial requirement, you can take out all the nouns and noun phrases. These are your candidate classes. The next stage is to decide which ones are classes in their own right and which are attributes. Often a lot of candidates can be reduced. As an exercise, I would recommend giving this a go and see where it takes you.


                            Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                            N Offline
                            N Offline
                            nstk
                            wrote on last edited by
                            #19

                            Thanks for your effort, I really appreciate this great help. I will indeed develop this as an exercise and if there is something to discuss I will write it here. :)

                            N 1 Reply Last reply
                            0
                            • N Nagy Vilmos

                              I'd argue the other way around. Company is not an attribute of a person, but a person - as in a contact - is an attribute of a company.


                              Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                              R Offline
                              R Offline
                              RobCroll
                              wrote on last edited by
                              #20

                              And all the customers who are buying products and services for their own personal use. They don't have companies so what do you do about them?

                              "You get that on the big jobs."

                              N 1 Reply Last reply
                              0
                              • N nstk

                                In a software for a company, we usually have customers, employees and suppliers in what regards humans. Therefore a reasonable (meaning a good one) OOP approach would be to have a class 'Persons' with attributes such as name, surname, address etc. and then let the classes 'Customers', 'Employees' and 'Suppliers' derive from the class 'Persons'. But, on a second thought there is a problem. How do we deal with customers and suppliers which are companies?

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #21

                                I would suggest looking at good MDM[^] designs as they obviously deal with it. I am not saying make yourself an MDM system (or buy/donwload one). I am just saying that MDM deals with so many 'entities' and they of course try to abstract out the overlapping info. I have never really looked into it too much but have dealt with MDM groups. Sometimes their 'naming' is off so it can be confusing, but in the end they get the job done. So if you find some info on MDM architecture you might stumble on to a good base class design.

                                Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                                1 Reply Last reply
                                0
                                • R RobCroll

                                  And all the customers who are buying products and services for their own personal use. They don't have companies so what do you do about them?

                                  "You get that on the big jobs."

                                  N Offline
                                  N Offline
                                  Nagy Vilmos
                                  wrote on last edited by
                                  #22

                                  You missed the BIG POINT earlier. A customer is a person or a company, A company also has a person as a contact. I almost feel an article...


                                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                  N R 2 Replies Last reply
                                  0
                                  • N Nagy Vilmos

                                    You missed the BIG POINT earlier. A customer is a person or a company, A company also has a person as a contact. I almost feel an article...


                                    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                    N Offline
                                    N Offline
                                    nstk
                                    wrote on last edited by
                                    #23

                                    Nagy Vilmos wrote:

                                    A customer is a person or a company, A company also has a person as a contact.

                                    What about putting the Persons class as a nested class in the Company class in that case? Complicated?

                                    N 1 Reply Last reply
                                    0
                                    • N nstk

                                      Nagy Vilmos wrote:

                                      A customer is a person or a company, A company also has a person as a contact.

                                      What about putting the Persons class as a nested class in the Company class in that case? Complicated?

                                      N Offline
                                      N Offline
                                      Nagy Vilmos
                                      wrote on last edited by
                                      #24

                                      Not a good idea. The attributes of a person - name, date of birth, sex, etc - are independent of the role they perform. A decent representation of a person will be reusable if you ignore how it is used. Similarly, the concept of a company is independent of the problem domain. A company has employees but, and this is true in real life as much as in a program, the employee does not have a company.


                                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                      1 Reply Last reply
                                      0
                                      • N nstk

                                        Thanks for your effort, I really appreciate this great help. I will indeed develop this as an exercise and if there is something to discuss I will write it here. :)

                                        N Offline
                                        N Offline
                                        Nagy Vilmos
                                        wrote on last edited by
                                        #25

                                        Here is a simple set of candidate classes:

                                                      +------------+
                                                      |  Customer  |
                                                      |            |
                                                      +------------+
                                                            |
                                                            v
                                        

                                        +------------+ +------------+ +------------+
                                        | Supplier |--->| Contact |--->| Person |
                                        | | | | | |
                                        +------------+ +------------+ +------------+
                                        |
                                        +------+--------+
                                        | impliments |
                                        +------------+ +------------+
                                        | Company | | Individual |
                                        | | | |
                                        +------------+ +------------+


                                        Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                        N 1 Reply Last reply
                                        0
                                        • N Nagy Vilmos

                                          Here is a simple set of candidate classes:

                                                        +------------+
                                                        |  Customer  |
                                                        |            |
                                                        +------------+
                                                              |
                                                              v
                                          

                                          +------------+ +------------+ +------------+
                                          | Supplier |--->| Contact |--->| Person |
                                          | | | | | |
                                          +------------+ +------------+ +------------+
                                          |
                                          +------+--------+
                                          | impliments |
                                          +------------+ +------------+
                                          | Company | | Individual |
                                          | | | |
                                          +------------+ +------------+


                                          Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                          N Offline
                                          N Offline
                                          nstk
                                          wrote on last edited by
                                          #26

                                          Shouldn't Person inherit from Contact? The arrow direction between them indicates the opposite situation.

                                          N 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups