1

00:00:00,990  -->  00:00:03,860
So you know understand inheritance.

2

00:00:03,870  -->  00:00:06,110
But the next question is designed to look.

3

00:00:06,260  -->  00:00:12,300
And the question would be how do you know which of the classes should be a superclass on which one should

4

00:00:12,300  -->  00:00:19,460
be at subclass for example can staff be a superclass and user be a subclass.

5

00:00:20,010  -->  00:00:25,980
Similarly if there is already a class which is Dola but your team member is available from an external

6

00:00:25,980  -->  00:00:32,850
library then would it be OK to make one of your classes a subclass of this other class.

7

00:00:32,970  -->  00:00:38,310
These are some important questions we shouldn't blindly create inheritance relationships which could

8

00:00:38,310  -->  00:00:39,990
be dangerous.

9

00:00:40,020  -->  00:00:44,880
There are a few tests that you need to apply and we will look at only one of those tests which is called

10

00:00:44,880  -->  00:00:53,820
us the easy test the easy test is the fast on the most fundamental tests that you need to apply to determine

11

00:00:53,820  -->  00:00:57,780
if classes can be related via inheritance.

12

00:00:57,780  -->  00:01:06,210
Let's look at it using older user classes just test Spaf is a user is used to check if stuff can be

13

00:01:06,220  -->  00:01:07,920
a subclass of user.

14

00:01:08,070  -->  00:01:14,280
That is what the staff is it hypoth user or in other words with a staff is it specialized Russian officer

15

00:01:14,280  -->  00:01:15,060
.

16

00:01:15,330  -->  00:01:16,420
Then we read it all.

17

00:01:16,560  -->  00:01:23,790
It completely makes sense that staff is a user on so they can be connected via inheritance.

18

00:01:23,790  -->  00:01:28,580
So use is more abstract and generalized stuff is more specialized.

19

00:01:28,890  -->  00:01:33,480
Next is whether they did a resistance which also sounds perfectly right.

20

00:01:33,900  -->  00:01:34,980
Next is it.

21

00:01:34,990  -->  00:01:37,950
It is a user which is also Karak.

22

00:01:37,950  -->  00:01:42,300
In fact this just is automatically valid due to the first two Tests.

23

00:01:42,330  -->  00:01:47,960
That is if staff is a user and editor is a staff then editor is also the user.

24

00:01:47,970  -->  00:01:54,330
In other words when you claim an inheritance tree from editor you would encounter use or at some point

25

00:01:54,330  -->  00:01:54,630
.

26

00:01:54,900  -->  00:01:59,970
And that means there is an easy relationship between editor and user.

27

00:01:59,970  -->  00:02:03,780
So obviously chief editor is also a user.

28

00:02:03,790  -->  00:02:08,720
The final two examples are two random examples which make perfect sense.

29

00:02:08,790  -->  00:02:10,150
Sojourned is a doctor.

30

00:02:10,290  -->  00:02:12,020
Triangle is a shape.

31

00:02:12,570  -->  00:02:13,670
Not that easy.

32

00:02:13,680  -->  00:02:17,080
Books in only one direction for example.

33

00:02:17,220  -->  00:02:24,450
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

00:02:24,810  -->  00:02:29,050
and does not how some of the capabilities of a staff member.

35

00:02:29,190  -->  00:02:36,180
So it test is a fundamental test which you need to apply to check for inheritance relationship.

36

00:02:36,180  -->  00:02:41,880
In addition there are also one or two other tests that you should apply and these are described in item

37

00:02:41,880  -->  00:02:43,870
16 of effective Java.

38

00:02:44,130  -->  00:02:45,920
But let's not worry about them for now.

39

00:02:46,200  -->  00:02:51,710
As it is a bit early to get into those concepts and we can look at them later.

40

00:02:52,260  -->  00:02:59,140
If is it test is failing then it means that you definitely must not use inheritance relationship.

41

00:02:59,280  -->  00:03:02,480
The easy test in the hostile examples shown here.

42

00:03:03,210  -->  00:03:08,410
That is a bookmark under you are two classes then bookmark is not a review.

43

00:03:08,430  -->  00:03:11,240
Similarly a review is not a bookmark.

44

00:03:11,790  -->  00:03:18,420
However a bookmark can have every view that is a bookmark and have an instance variable which is off

45

00:03:18,420  -->  00:03:26,220
pipe review and this case to say that there is has a relationship between them and object oriented programming

46

00:03:26,220  -->  00:03:26,310
.

47

00:03:26,340  -->  00:03:33,270
Such a relationship is also referred to as composition and in some cases composition is preferred over

48

00:03:33,330  -->  00:03:34,550
inheritance.

49

00:03:34,880  -->  00:03:40,340
It is actually the main subject of item 16 and we can look at it later.

50

00:03:40,350  -->  00:03:46,270
The final example shown here is about the relation between two classes bathroom on top.

51

00:03:46,290  -->  00:03:52,800
Now if you see double extends about the row it kind of sounds reasonable but as soon as you play easy

52

00:03:52,800  -->  00:03:57,730
test you will see that the relationship does not work in either direction.

53

00:03:57,780  -->  00:04:02,910
Bathroom has up is the right relationship and that's about it.

54

00:04:02,940  -->  00:04:06,640
Do make sure to always play the easier test.

55

00:04:06,660  -->  00:04:07,020
Thank you
