1

00:00:01,140  -->  00:00:08,970
Let's not implement couple of manager classes if you recall manager classes include business logic which

2

00:00:08,970  -->  00:00:12,130
would include code to instantiate entities.

3

00:00:12,570  -->  00:00:18,840
So they'll begin creating manager classes by writing methods that would instantiate entities that we

4

00:00:18,840  -->  00:00:20,140
created.

5

00:00:20,520  -->  00:00:26,050
The methods we laid will be used later from the day dustoff class which we rewrite later.

6

00:00:26,790  -->  00:00:31,750
The manager classes we will write will be named as User Manager and bookmark manager.

7

00:00:32,340  -->  00:00:35,850
USE IT manager will good business logic related to users.

8

00:00:35,960  -->  00:00:40,630
Well the plant manager billing good business logic related to bookmarks.

9

00:00:40,650  -->  00:00:44,820
One main thing to note about Manager classes is that they are stateless.

10

00:00:44,940  -->  00:00:51,330
That is they don't mean in any instance variables so you don't need to create an instance of them and

11

00:00:51,330  -->  00:00:55,950
instead can maintain them as static utility classes.

12

00:00:56,040  -->  00:01:04,620
However for managers it's recommended to not use static utility classes instead of just one single instance

13

00:01:04,950  -->  00:01:07,690
of each of the manager classes.

14

00:01:07,710  -->  00:01:14,900
The reason for this is in some projects manager classes implement an interface and indorsing not yours

15

00:01:14,900  -->  00:01:15,230
.

16

00:01:15,270  -->  00:01:22,920
You cannot use tactic utility classes as static matters in such classes cannot override or hide instance

17

00:01:22,920  -->  00:01:24,560
methods in an interface.

18

00:01:25,260  -->  00:01:31,630
So the recommended method is to create a single instance of the manager class and this is achieved by

19

00:01:31,650  -->  00:01:38,190
using a design pattern called Singleton partan a singleton pattern is simply a design pattern that would

20

00:01:38,280  -->  00:01:42,270
ensure that exactly one object is created or no more.

21

00:01:42,550  -->  00:01:49,720
And it also provides a global point to access the object store manager classes are basically singletons

22

00:01:49,730  -->  00:01:50,180
.

23

00:01:50,970  -->  00:01:55,010
So let's get started and see how this is done.

24

00:01:55,410  -->  00:01:58,580
Krust let's create a new package for our managers.

25

00:01:59,040  -->  00:02:02,620
So let's just right click here.

26

00:02:06,300  -->  00:02:07,890
So it would be calm semantics.

27

00:02:07,910  -->  00:02:09,570
There really are dock managers

28

00:02:12,300  -->  00:02:14,640
let's begin with creating the user manager Plus

29

00:02:22,320  -->  00:02:24,930
just a short note on the naming convention here.

30

00:02:25,230  -->  00:02:30,680
Fund manager is typically the last names would end with the manager.

31

00:02:30,720  -->  00:02:36,260
Some programmers also use the term service instead of manager as managers to define the service here

32

00:02:36,270  -->  00:02:37,150
.

33

00:02:37,200  -->  00:02:42,780
However it's just a matter of choice and in my opinion it's really not important whether we use the

34

00:02:42,780  -->  00:02:49,530
term manager ourselves to end the class name only important thing to do as follow what your team is

35

00:02:49,530  -->  00:02:50,150
doing.

36

00:02:50,400  -->  00:02:52,920
If your team is using manager then go with manager.

37

00:02:53,130  -->  00:02:55,950
If your team is using service then go with service.

38

00:02:56,430  -->  00:03:03,660
OK first let's implement a singleton related code as part of implementing Singleton we to have a private

39

00:03:03,660  -->  00:03:04,690
constructor.

40

00:03:05,130  -->  00:03:11,050
So let's create a private constructor.

41

00:03:11,370  -->  00:03:17,700
We know that having a private constructor implies that one cannot instantiate the class so the class

42

00:03:17,700  -->  00:03:22,060
of user manager cannot create an instance of User Manager.

43

00:03:22,140  -->  00:03:24,170
So that's what we want for a singleton.

44

00:03:24,180  -->  00:03:27,920
We don't want our clients to create instances freely.

45

00:03:28,050  -->  00:03:32,270
So for Singleton we said that only one object needs to be created.

46

00:03:32,580  -->  00:03:37,530
Now since it's a private constructor we cannot create an instance of it.

47

00:03:37,560  -->  00:03:41,890
Now how do you create that single instance for a singleton.

48

00:03:41,970  -->  00:03:48,510
So for that only way to do it as since it's a private constructor the single object has to be created

49

00:03:48,510  -->  00:03:50,220
from within this class.

50

00:03:50,220  -->  00:03:53,130
So that's done from a method and we can.

51

00:03:53,130  -->  00:03:58,700
The convention is to collect as get instance.

52

00:03:59,250  -->  00:04:07,220
Now this method has to return an object of type user manager.

53

00:04:07,540  -->  00:04:11,220
OK so that's the return type.

54

00:04:11,220  -->  00:04:18,270
Now that needs to be public since one cannot create an instance of user manager.

55

00:04:18,270  -->  00:04:20,310
It needs to be a static method.

56

00:04:20,940  -->  00:04:26,930
So this is the method that would return the single instance of user manager.

57

00:04:27,300  -->  00:04:31,670
OK so that and Ipperwash the global point of access.

58

00:04:31,710  -->  00:04:37,290
Now you can create an instance here but let's do it here.

59

00:04:37,830  -->  00:04:45,990
So let's create a pirate variable that type of that variable has to be user manager and it's call the

60

00:04:45,990  -->  00:04:48,030
variable as instance.

61

00:04:48,350  -->  00:04:52,030
And let's create the instance here.

62

00:04:52,060  -->  00:04:52,550
Sorry

63

00:04:57,060  -->  00:05:04,820
Now since this is an instance variable we cannot access it from here so is if we want to access it from

64

00:05:04,820  -->  00:05:05,680
a static method.

65

00:05:05,690  -->  00:05:07,840
It needs to be static too.

66

00:05:08,690  -->  00:05:12,730
So that's how we create an instance or we can actually create it here also.

67

00:05:12,950  -->  00:05:16,070
But we are creating it here in the declaration itself.

68

00:05:16,130  -->  00:05:23,350
So over here all we do as we're done instance.

69

00:05:24,360  -->  00:05:32,030
So now what happens is whenever the client code says User Manager Daag get instance on the very first

70

00:05:32,030  -->  00:05:36,730
time it does that the JVM actually loads the class Lord of Lords.

71

00:05:36,760  -->  00:05:41,790
Does the user manager class into memory at the same time it will also exit your desk.

72

00:05:42,020  -->  00:05:45,950
The first statement and an instance will be created.

73

00:05:45,990  -->  00:05:51,200
So that happens when the when this method is invoked for the very first time.

74

00:05:51,290  -->  00:05:56,450
So by the time the method is invoked the instance variable is already initialized with the object.

75

00:05:56,560  -->  00:06:03,320
OK and we are just returning the object and this is a good way of creating the singleton.

76

00:06:04,000  -->  00:06:08,410
You know there are a couple of other minor variations also for creating singletons.

77

00:06:08,710  -->  00:06:15,200
I mean once you are done with the course you can check out Chapter 5 and head first design patterns

78

00:06:15,200  -->  00:06:15,470
book.

79

00:06:15,480  -->  00:06:21,770
It's a very good book and you can check out the chapter 5 which is on specif specifically for us on

80

00:06:21,770  -->  00:06:26,930
singletons and it explains these other minor variations also.

81

00:06:27,020  -->  00:06:33,520
So but the approach we followed is good and you can follow this approach.

82

00:06:33,950  -->  00:06:36,440
So that's how you create a singleton.

83

00:06:36,590  -->  00:06:44,710
Next let's create a method for instantiating user Blake user.

84

00:06:45,290  -->  00:06:46,230
Let's call the methods.

85

00:06:46,380  -->  00:06:51,520
Create users since we want to create an user instance.

86

00:06:51,750  -->  00:06:55,940
So that's how all the instance variables.

87

00:06:56,080  -->  00:06:57,870
Let's click on this.

88

00:06:57,870  -->  00:07:04,220
So these are the variables ID email password so id is long

89

00:07:20,390  -->  00:07:24,350
and user type.

90

00:07:24,360  -->  00:07:27,850
So this method will be invoked later from the dust or class

91

00:07:30,570  -->  00:07:31,920
of.

92

00:07:32,300  -->  00:07:33,900
So what we have.

93

00:07:34,160  -->  00:07:38,940
And so let's go ahead and say user user

94

00:07:42,660  -->  00:07:44,010
now a user

95

00:07:48,800  -->  00:07:49,300
id

96

00:07:55,730  -->  00:07:58,260
say trust me

97

00:08:14,270  -->  00:08:21,860
you think we missed the password here or said email.

98

00:08:21,990  -->  00:08:25,460
So Id email password first name last name

99

00:08:28,500  -->  00:08:31,440
and gender and user name.

100

00:08:31,500  -->  00:08:33,810
So we have all of them sent here.

101

00:08:33,920  -->  00:08:46,970
So let's just say written user so that the User Manager class next lets create a bookmark manager and

102

00:08:47,070  -->  00:08:47,850
managers

103

00:08:47,850  -->  00:08:57,130
.

104

00:08:57,530  -->  00:08:59,860
So once again thats create a singleton

105

00:09:03,070  -->  00:09:05,030
thats the private constructor

106

00:09:11,380  -->  00:09:24,730
its the public access matter private static.

107

00:09:28,090  -->  00:09:32,660
So just just returns the instance.

108

00:09:33,150  -->  00:09:40,110
Ok so thats the singleton code for creating Singleton host lets create the movie method to create a

109

00:09:40,110  -->  00:09:45,540
movie.

110

00:09:49,160  -->  00:09:59,910
Just open the movie Close but Mark has some valuable Speidel and profile you are in a

111

00:10:08,070  -->  00:10:09,630
movie class as a release.

112

00:10:09,650  -->  00:10:11,830
Your cast director's

113

00:10:26,420  -->  00:10:28,160
gender and I am beby rating

114

00:10:32,640  -->  00:10:39,690
.

115

00:10:40,280  -->  00:10:43,070
So let's just go ahead and create the movie instance

116

00:10:46,500  -->  00:10:52,220
in that same boat movie we movie

117

00:10:56,000  -->  00:10:58,650
you know said the loose

118

00:11:11,210  -->  00:11:12,110
release either

119

00:11:28,050  -->  00:11:29,760
so I guess that's about it.

120

00:11:29,810  -->  00:11:33,010
So it's a certain movie.

121

00:11:33,020  -->  00:11:36,640
So that's how you would create a movie.

122

00:11:36,650  -->  00:11:43,040
Similarly we need to create methods for creating both book and also grappling instances.

123

00:11:43,220  -->  00:11:48,340
So in the interest of time I'm not going to the monsters creating those matters as that pretty identical

124

00:11:48,390  -->  00:11:48,700
.

125

00:11:49,010  -->  00:11:51,810
So just go ahead and create them yourself.

126

00:11:51,810  -->  00:11:57,680
I will also do it offline and we'll come back to just show you the quarter.

127

00:11:59,420  -->  00:12:05,940
So here is the Create book method and it's creating a book instance and setting all the feels like the

128

00:12:05,930  -->  00:12:11,240
ID title publication your publisher authors genré iron Amazon rating.

129

00:12:11,580  -->  00:12:18,410
OK so that's the book instance and here is the method create weblink and we are creating an instance

130

00:12:18,410  -->  00:12:26,510
of a blank on one side inserting ID tightly and the two feel specific to Webling which are you out host

131

00:12:26,510  -->  00:12:26,950
.

132

00:12:27,410  -->  00:12:29,630
So those are the two manager classes.

133

00:12:29,750  -->  00:12:33,220
Later we'll be adding more code to these two classes.
