It depends on the requirements of the project and how you are translating the requirements to design.
You are talking about three different principles of Object Oriented Programming.
Single Responsibility -
- A Class should have only one responsibility and only one reason to change. This is also known as having high 'cohesion'.
- Another way of looking at it is that the coupling - dependence on other classes- should be minimal preferably zilch.
In this context orthogonal classes or independent classes makes sense
Inheritance -
- Inheritance comes into picture when you want to reuse a certain classes functionality and make a new class out of it. In other words if you want to extend classes capabilities. IF you want to keep certain functionality of the class intact and add new functionality or properties you don't have to re-write the class definition instead you just inherit from the existing class and make a new one.
The class from which properties are inherited is called super/base class. and the class which inherits is derived class. If 'B' inherits from 'A' then we say 'B' is-kind-of 'A'. 'A' is base class 'B' is derived
Composition
- Composition means a class can have an object of another type as its member.if a class A has a member of type Class 'B' . Then there is a composition relationship between 'A' and 'B'. 'A' -has- 'B'.
Let see examples
Lets say i have a Class Home
Home has Rooms
Home has Furniture
Home has electronics
Single Responsibility Example
although Furniture and electronics belong to a home but they are completely independent of each other. A change in one will not effect the other. Hence there is loose coupling between the two and they are orthogonal to a large extent.
Inheritance example
Home also had guest room(s), bed room(s)
So Guest Room will inherit from Room
Bed Room will inherit from Room
Class GuestRoom : public Room { }
Class BedRoom : public Room { }
Composition example
Room Will have furniture and electronics
class Room {
vector<furniture> furniture_vec;
vector<electronics> electronics_vec;
.
// other members
}
There are other object oriented principles which come into picture when trying to design an application. Reading a good book on OOPs principles and looking at some examples will clarify these concepts further.