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?

Recommended Answers

All 4 Replies

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

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

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.