So you know understand inheritance. 2
But the next question is designed to look. 3
And the question would be how do you know which of the classes should be a superclass on which one should 4
be at subclass for example can staff be a superclass and user be a subclass. 5
Similarly if there is already a class which is Dola but your team member is available from an external 6
library then would it be OK to make one of your classes a subclass of this other class. 7
These are some important questions we shouldn't blindly create inheritance relationships which could 8
be dangerous. 9
There are a few tests that you need to apply and we will look at only one of those tests which is called 10
us the easy test the easy test is the fast on the most fundamental tests that you need to apply to determine 11
if classes can be related via inheritance. 12
Let's look at it using older user classes just test Spaf is a user is used to check if stuff can be 13
a subclass of user. 14
That is what the staff is it hypoth user or in other words with a staff is it specialized Russian officer 15
. 16
Then we read it all. 17
It completely makes sense that staff is a user on so they can be connected via inheritance. 18
So use is more abstract and generalized stuff is more specialized. 19
Next is whether they did a resistance which also sounds perfectly right. 20
Next is it. 21
It is a user which is also Karak. 22
In fact this just is automatically valid due to the first two Tests. 23
That is if staff is a user and editor is a staff then editor is also the user. 24
In other words when you claim an inheritance tree from editor you would encounter use or at some point 25
. 26
And that means there is an easy relationship between editor and user. 27
So obviously chief editor is also a user. 28
The final two examples are two random examples which make perfect sense. 29
Sojourned is a doctor. 30
Triangle is a shape. 31
Not that easy. 32
Books in only one direction for example. 33
Is a user but the user is not as tough as we know that a regular user is simply a user of the website 34
and does not how some of the capabilities of a staff member. 35
So it test is a fundamental test which you need to apply to check for inheritance relationship. 36
In addition there are also one or two other tests that you should apply and these are described in item 37
16 of effective Java. 38
But let's not worry about them for now. 39
As it is a bit early to get into those concepts and we can look at them later. 40
If is it test is failing then it means that you definitely must not use inheritance relationship. 41
The easy test in the hostile examples shown here. 42
That is a bookmark under you are two classes then bookmark is not a review. 43
Similarly a review is not a bookmark. 44
However a bookmark can have every view that is a bookmark and have an instance variable which is off 45
pipe review and this case to say that there is has a relationship between them and object oriented programming 46
. 47
Such a relationship is also referred to as composition and in some cases composition is preferred over 48
inheritance. 49
It is actually the main subject of item 16 and we can look at it later. 50
The final example shown here is about the relation between two classes bathroom on top. 51
Now if you see double extends about the row it kind of sounds reasonable but as soon as you play easy 52
test you will see that the relationship does not work in either direction. 53
Bathroom has up is the right relationship and that's about it. 54
Do make sure to always play the easier test. 55
Thank you