So we implemented a major feature in the last lesson. 2
No we are going to implement another important feature which is to mark certain bookmarks as kid friendly 3
. 4
Nice thing is we already know the feature and the design that goes with it as we were using Treo as 5
a case study in learning the Object-Oriented concepts. 6
And just to recap the main idea is to maintain some prefab on the home page just pockets that is under 7
this new tab. 8
You will see only bookmarks that are suitable for kids. 9
The way it works is we have regular bookmarks for all kinds of users but one staff members like editors 10
and chief editors are using the system. 11
Then they will see a special link for marking most kinds of bookmarks as kid friendly for certain bookmarks 12
which are clearly not eligible for kid friendly status. 13
Some special things will not be displayed. 14
Examples would include bookmarks falling under categories such as January. 15
In case you skipped the chapters on object oriented programming then you can check out the first lesson 16
in the chapter that covers abstract classes and interfaces. 17
That lesson was this requirement. 18
But I guess the recap that we just did what most of the requirements. 19
So it's a nice feature as having a separate tab exclusively for it is very useful. 20
Now here is a class diagram for implementing this feature and we already implemented this and it is 21
the missing pieces are the two methods generate profile you are an easy kid friendly eligible. 22
Let's not worry about Jondrette profile you are for now and let's just implement easy get friendly eligible 23
method. 24
Once we implement East get friendly eligible method we will then implement the functionality for marking 25
bookmarks as kid friendly. 26
No here is good for any eligibility requirement for movies. 27
If the movie is either horror or Thriller then the matter to read and falls otherwise it should read 28
and true. 29
Similarly for books if the book is either a philosophical or a self-help book then the method Trivett 30
and falls. 31
Finally with ramblings The method should read and a false. 32
If the website is an other site not to implement is good for any eligible method we will follow what 33
is called s driven development which is in short referred to as P-Diddy. 34
Best do do double up ment is a software development process where the desk is is written before the 35
functional code is written for a new feature. 36
So you don't write the functional code first and then the best guess later you would write the desk 37
as fast. 38
And here are the main steps. 39
So you are right the desk is along with some initial code that would cause the test to fail. 40
Then you would write enough code to pass the test. 41
You can repeat this process of. 42
That's fast approach to incrementally add more functionality. 43
That is you would add more deaths and then more logic and let us pass. 44
Here are some real benefits. 45
And you are already familiar with this slide as it is taken from the eclipse chapter. 46
When we were discussing about unit tests so we know that such automated does will prevent new code from 47
breaking the system. 48
Basically it ensures program correctness at all points of time and that will improve programmer's confidence 49
. 50
But one important additional benefit of DDT is that it can also help you in better designing your methods 51
. 52
That's because DDT forces you to think through all the scenarios that would cover all the feature requirements 53
. 54
So you just tend to have a different thought process when doing. 55
First approach as opposed to a later approach. 56
So basically you are driving your design I think as you put it into practice and start using it regularly 57
. 58
Then you will be able to better appreciate its approach. 59
OK that's DDD and let's get started now. 60
So first thing that we need to do as I'd ease kid friendly eligible matter in the bookmark class. 61
It really added as an abstract matter. 62
So let's just go ahead and open the bookmark class. 63
So there is a shortcut to open a class with this control shift. 64
Our So this is a shortcut and let's just type and bookmark this right here at the top. 65
So that's Control shift. 66
And let's make this abstract. 67
If you recall this is supposed to be abstract but since we are adding that abstract method only now 68
so we're making the class abstract now so it will be public 69
so that's that is kid friendly and vegetable matter and let's just provide the implementation and weblink 70
selection is going to control shofer are let's do a blank. 71
OK. 72
Here it is. 73
Now we need to implement it. 74
So that's why it's giving compilation error. 75
So let's say I unimplemented methods. 76
So here is the stub. 77
And let's just return true for now. 78
Will be clear soon. 79
Now let's just go ahead and I had a test case for this because we are going to follow the best driven 80
approach. 81
So let's just go here and add a new folder called test. 82
So source folder called best and you might recall it from our G-Unit Allison and Eclipse chapter. 83
Now within this let's add a package and it has to be the same package as the entities as of eyeblink 84
because we are going to provide a desk for a web link. 85
OK. 86
So the package name will be Chrome 87
and Cadiz. 88
Now that's ired a G-Unit desk case since we are testing eyeblink needs to be Rabbe wabbling test. 89
So that's the convention and we need to load the class which we are going to test. 90
So it will be Lenk. 91
So this is the class under test. 92
And then hit next here. 93
If you're not providing the class under test then this will not be highlighted here and you'll see only 94
finish. 95
So you should select the class under test head next. 96
And this is the method that we want to test and it says I. 97
G-Unit library to the barre But let's just say ok and G-Unit has been added here and this is the template 98
class. 99
Yes. 100
If we run this it would fail not to think through our test cases. 101
So the requirement is that this method is different the eligible should return false. 102
If it's an adult website. 103
So let's look at weblink class and see what field it has. 104
It has a u r l it has a host and if you look at bookmark class it also has a title. 105
Let's look at all of this here. 106
So it has a title. 107
So those are the three fields that we have. 108
So what we can do is we can look for some keywords in these fields and if the keyword is present we 109
build it and false otherwise we will return true. 110
So let's take on our world as the key words are whatever your imagination suggests. 111
So we can have the logic in this. 112
If the word porn is present anywhere in the water or in Tipler then we see it and falls Similarly if 113
the key word either appears anywhere in the hostname then where it involves But if it appears anywhere 114
else in the order other than the host name then deleted it and true. 115
Similarly if it if it appears only in title then also it untrue since we are following just doing the 116
will up meant we will have to frustrate our best guesses and we will then write the actual logic. 117
So let's do that. 118
So let's go back into our Webling test and let's write five best cases. 119
Let's just put some comments first. 120
Just one 121
. 122
So for just one we will test if the key were born as and the you are ill. 123
In this case it has to return a false. 124
Next we will check f porn and Titan can never blink instance. 125
And in this case also the matter has to return false. 126
You know the third scenario as our gold in Horst. 127
Right. 128
So for does it has to return false. 129
Now our dirt in your order but not in host this hitcher construe 130
and only in this case also I took control. 131
So let's just go ahead and build these test cases. 132
So basically what we are what we have to do is create an instance of a weblink. 133
And so that would be the book and then we will execute. 134
We will invoke the east kid friendly eligibility method and then we but it does the output. 135
So first let's create an instance so that would be the input and we have to create an instance for that 136
let's just going to data store here because there is already some code for creating an instance you're 137
just let's use this just won't go back. 138
No this is a mark of sorted rodent's a weblink. 139
So Paul and you are of that so let's just go here. 140
Let's just put it here. 141
It's on. 142
So that's the good. 143
So let's invoke a blank Dorward ease get friendlier richer. 144
Now this returns a boolean. 145
So let's assign it to a boolean reliable and that's quite at ease. 146
Good friendly eligible. 147
So it has to return a false. 148
So we will use this method call as Surt falls from the asset class here which is important. 149
Big group at amateur's. 150
And the second parameter is the east kid friendly eligible method and if it returns false then we are 151
good. 152
But if in case if it returns true then it means that something is wrong. 153
And then if needed then we need to print a nice message. 154
So let's just say for porn on some meaningful message and you are still 155
Maastricht and fonts. 156
OK. 157
So let's go ahead and ride the second best. 158
So if this returns true if this method returns are true for this instance then this message will be 159
strong. 160
OK. 161
So it's right the second best. 162
Just remove this 163
and the second just born has to be entitled. 164
So let's just look at here. 165
And for on AM. 166
Is good for and true and it's also remove this here beaming anger. 167
So now let's copy this whole thing and let's build a third discus. 168
Now this is about Horst appearing and host sort of just changed this back to. 169
And here is the host name. 170
So let's just make it. 171
I don't want assistance 172
for I don't. 173
Host. 174
He's good for an angiogram was written for. 175
So this is good for the fourth Test. 176
Hoes are dead in your world but not in whole Sparta so he can hide it here under knocking holes. 177
But so this is also good. 178
So let's just say four hundred in your honor but not host not host vodka for this. 179
It needs to return it. 180
True. 181
What does the matter. 182
Has it done it true. 183
Because the term our dirt is not appearing in host it needs to return. 184
True. 185
So for truculence concept true if East get friend eligible is assigned true then we are good. 186
If not it will throw this exception and it will or must return true. 187
Yeah we need to change this now. 188
The final test here 189
just sit in in the title The key word adult should appear in title. 190
Yeah. 191
So this is good. 192
For and Dyken must return true. 193
So those are all the best guess is that we have now let's just go ahead and run this wabbling best proceed 194
. 195
That is in error because we still did not tried the method itself or did not build our logic. 196
So it says here in the US District has failed. 197
So let's just go ahead and build our logic now. 198
Let's go here 199
on Daines. 200
So Titlist by free an bookmarks so we cannot access or indirectly. 201
So we have to use some of this get Teicher we have to use the get method here and to get her. 202
So let's just go ahead and run this again 203
. 204
So now as you can see the first two deaths how free or how fast. 205
Because we have written the logic for porn but it failed at the third one because at the third one we 206
are passing our word. 207
And that is unhorsed and we still do not have the logic for that. 208
So it's time to write logic for the third one. 209
So let's just say host Undine's. 210
So even in this case it has to written as far as if the host has in-groups the key word order. 211
So let's just go back. 212
So it passed but it did the fourth one failed for the fourth one we are passing under a new order but 213
not host part. 214
Oh I think it's because of this which has to be beaming. 215
It's just us. 216
OK. 217
So that was just an error 218
. 219
So now for sure it will work. 220
So as you can see there are zero errors and zero failures. 221
So we are good. 222
So that's how that's one double up and is done. 223
So we have written the past cases first and then we how bad our logic under that is how passed. 224
OK. 225
So that's for eyeblink. 226
So let's just do four book on movie. 227
So let me do it offline and then I'll come back and show you the code. 228
OK. 229
Here is the more we test. 230
So that's the best guess for testing. 231
The movie NDB and here is a method. 232
So we are testing east kid friendly eligible method and here that here are the two test cases. 233
So if you recall the condition is that if the movie is either a horror movie or a thriller movie then 234
the method should read and false. 235
So that was a condition and that's what we are testing here. 236
So if that returns false then we are good and we are doing and assert false as we did for the wabbling 237
. 238
So so that's those are the two tests. 239
And let's just go here three and here we are simply checking f genré is a. 240
Equals equals horror our effort equals thriller than really good return for us which means that it's 241
not good friendly. 242
And so this is the book Best And For the book best the condition is that the books should not be either 243
a philosophy book or self-help book. 244
OK so once again we are looking at the genre field and we have two test cases for that. 245
And so if we're going to this method it's very similar to the movie logic. 246
So that's how you do best Doogan double up. 247
You write that as Cozzens first and then you die. 248
And the initial test should fail and then you build the logic and then that well that will pass the 249
test. 250
So that's how you would do it. 251
And if any Duggal a person if they mess up what with the logic here then when the tests are run it is 252
very likely that they will fail and then they will hold the double up or do fix the issue. 253
OK. 254
I also want to say that just go ahead and check out the frequently asked questions and G-Unit site and 255
they have a real good compilation of frequently asked questions. 256
So finally I'm also including a few important book references in the resource section and you may want 257
to buy them at some point if you feel necessary. 258
And that's about it for now.