No, I understand the is a/has a relationship of the list I created in the real world. What I was asking is this:
1 2 3
|
class Mammal{};
class Lion:public Mammal{};
|
The relationship between Mammal and Lion is "is a", which means it implies a public inheritance between base Mammal and derived Lion. BUT, although the relationship is "is a" what if I decide to make the inheritance private or protected,
1 2 3
|
class Mammal{};
class Lion:protected Mammal{};
|
1 2 3
|
class Mammal{};
class Lion:private Mammal{};
|
because I simply don't want users to touch the base class from main() for whatever reason.
Again, I also understand that I can make member variables and methods in base/derived class private/protected as needed in order to keep away from public access from main().
So although the relationship is in a "is a" relationship, that I intentionally made the inheritance protected or private. Will that be a red flag to someone and will they say what in the world are you doing, that is supposed to be a "is a" relationship and that should NEVER be in a private or protected relationship. Is it BAD coding to make that public inheritance change to protected or private?
Once I change the inheritance to protected or private, I no longer make the "is a" relationship between Mammal and Lion and the relationship becomes "has a" in THEORY. The Lion "is a" no longer a mammal then. And even though the code will work perfectly fine and I will fulfill my desire to not have users/newbies access and modify members of class base from main().
There is a third relationship: "Uses A" |
I have not read anything about a 3rd relationship ("Uses A"), but that sure sounds a lot like an example the book gave. A Car class that inherits from Motor class can have a bottleneck in today's world where we have electric motors, so the solution was to use composition/aggregation to include an ElectricMotor within the class as a member. No mention of "Uses A" though.
So then, of course my brain runs wild and thinks well then we really can't predict many things in future advances. We can use a pig to grow a modified human heart and it can grow multiple organs of sorts. Humans might have quantum brains or specialized limbs appended. So why not just make many things or everything aggregation then.