0

I'm trying to design my UML diagram but I'm not sure about something.

If I have a derived class that belongs to two other classes will the two other classes inherit the features of the base class?

For example class Vehicle_Details inherits features from class People(is-a relationship AKA inheritance) while class visitor and class personnel has-a (i.e owns - composition) class Vehicle_Details. Will the last two class have the same access to class People like class Vehicle_Details does?

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by knight fyre
0

depends on whether vehicle_Detals derived from People as public or private

class People
{
   // blabla
};

class vehicle_Detals : public People
{
   // blabla
};

class Visitor : public vehicle_Detals
{
  // blabla
};

In the above Visitor has the same assess to People as vehicle_Details has, in otherwords it has access to all public and protected data, but does not have access to private data.

class People
{
   // blabla
};

class vehicle_Detals : private People
{
   // blabla
};

class Visitor : public vehicle_Detals
{
  // blabla
};

In the above, Visitor does not have access to anything in People

0

Thanks for clearing that up but looking deeper into the issue that solution would not solve my problems anyway.

0

For example class Vehicle_Details inherits features from class People(is-a relationship AKA inheritance) while class visitor and class personnel has-a (i.e owns - composition) class Vehicle_Details. Will the last two class have the same access to class People like class Vehicle_Details does?

You are trying something like below?

class People { ... };
class Vehicle_Details : public People { ... }; //inheritance

class Visitor {
...
Vehicle_Details visitor_r; //composition by object
};

class Personnel {
...
Vehicle_Details personnel_r; //composition by object
};

Your question will then be will visitor_r and personnel_r variable in Visitor and Personnel class be able to access People class like Vehicle_Details class do? You are talking about data member or member function access in People class?

0

That is the situation I was describing yes but to implement it in my UML diagram would be illogical so it doesn't make sense to use this method. But I know it will work if I do need this in an actual program.

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.