"has a" vs "is a" relationships

This is a discussion on "has a" vs "is a" relationships within the C++ Programming forums, part of the General Programming Boards category; What is the difference between a "has a" and "is a" relationship?? I can't seem to find it in my ...

  1. #1
    Registered User carebear's Avatar
    Join Date
    May 2006
    Location
    Missouri
    Posts
    7

    "has a" vs "is a" relationships

    What is the difference between a "has a" and "is a" relationship?? I can't seem to find it in my book or by searching!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    Quote Originally Posted by carebear
    What is the difference between a "has a" and "is a" relationship?? I can't seem to find it in my book or by searching!
    What are you taking a test? You know it's ok to group these questions into one post... infact... it's a whole lot better to do so.

    A "Has a" relationship deals with object data members in classes. For instance
    Code:
    class myClassA;
    
    class myClassB {
       public:
          myClassA getA() { return myAObj; }
       private:
          myClassA myAObj;
    };
    In this example. myClassB "has a" myClassA object.

    An "is a" relationship deals with inheritance.
    Code:
    class myClassA;
    
    class myClassB : public myClassA {};
    In this example, myClassB "is a" myClassA obj as well as a myClassB object.
    Sent from my iPadŽ

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Ah, we explained this in the earlier thread, kinda...

    I think a "has a" relationship between classes is when class A contains a class member B. For instance every Person has a Pet.
    Code:
     class Person {
    private:
    Pet my_pet;
    };
    An is a relationship deals with inheritance; it's when Class B derives from class A.
    Code:
     class Vehicle {  };
    class Bus : public Vehicle { };
    You see? A Bus is a Vehicle. It works like that.
    Last edited by whiteflags; 05-03-2006 at 02:02 AM.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    The classes:

    class Car;

    class Wheel;

    class Convertible;


    Question 1: should Convertible be derived from the class Car? "Is a" Convertible a Car, i.e. is Convertible going to share the same properties and functions as Car with some extra stuff?

    Question 2: should Wheel be derived from Car? "Is a" Wheel a Car? Nope. So, the functionality of a Car probably won't apply to a Wheel. However, a Car "has a" wheel. So, that would indicate aggregation would be appropriate, i.e. the Car class could have a member which is a Wheel object.

  5. #5
    Registered User carebear's Avatar
    Join Date
    May 2006
    Location
    Missouri
    Posts
    7
    Oh, I figured I should address each thing seperately, I'll keep that in mind if I have a few questions to ask at once again. This is the last one I'm stumped on though lol. And yeah, I have searched my little heart out on just a few things and figured I'd just ask for some help on the ones that had me stumped.

    Thanks so much, you guys have been so helpful! I was starting to seriously stress on not being able to figure out these last few questions lol. Again, I really appreciate it

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    What are you taking a test? You know it's ok to group these questions into one post.
    Hmmm...sounds like someone is cheating.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    Quote Originally Posted by 7stud
    Hmmm...sounds like someone is cheating.
    Heh, nah... it's like 2 AM in Missouri. I don't think carebear is testing right now.

    If anything, they're studying, or they're answering a handout... in the latter case, it's pretty cheap, but too innocent for me to call cheating.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Ever hear of a take home test? Graded homework assignment?

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    Not in college.

    Not in my courses, anyway. Duly noted, though.

    EDIT: Graded homework assignments are poo. It's open book, open notes... personally I think a person that doesn't research themselves deserves a slap on the wrists, but if their interest in the subject is so shallow that they don't care to pay attention or take notes, then I don't think they deserve their GPA rocked if they end up switching majors to something they like better.

    It's not like they'll get to the top of the Programming career ladder on the backs of people who keep telling them the answers.
    Last edited by SlyMaelstrom; 05-03-2006 at 02:16 AM.
    Sent from my iPadŽ

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Even if that is the case, we are not the moral police, and we certainly won't save his grade by answering questions on general theory. Plus we're not so mean as to be like! "SMELLS LIKE HOMEWORK! B&!" Not that I have anything against you.

    ..Trying to be funny mostly. It's late here.
    Last edited by whiteflags; 05-03-2006 at 02:15 AM. Reason: HOEWORK: best typo ever

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21