Investigating More Using a More Comprehensive and Better Organized Version of Our Sample Project

Basics of Java 9 Modularity (JPMS or Project Jigsaw) Chapter 2- Some Problems We Face Using Only Packages Before Java 9
7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€66.45
List Price:  €94.93
You save:  €28.48
£55.32
List Price:  £79.03
You save:  £23.71
CA$98.04
List Price:  CA$140.06
You save:  CA$42.02
A$107.72
List Price:  A$153.89
You save:  A$46.17
S$94.09
List Price:  S$134.42
You save:  S$40.33
HK$544.68
List Price:  HK$778.15
You save:  HK$233.46
CHF 61.92
List Price:  CHF 88.46
You save:  CHF 26.54
NOK kr774.79
List Price:  NOK kr1,106.89
You save:  NOK kr332.10
DKK kr495.67
List Price:  DKK kr708.13
You save:  DKK kr212.46
NZ$118.82
List Price:  NZ$169.76
You save:  NZ$50.93
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,339.40
List Price:  ৳11,913.94
You save:  ৳3,574.54
₹5,914.23
List Price:  ₹8,449.26
You save:  ₹2,535.03
RM311.24
List Price:  RM444.65
You save:  RM133.41
₦118,083.62
List Price:  ₦168,698.12
You save:  ₦50,614.50
₨19,391.36
List Price:  ₨27,703.14
You save:  ₨8,311.77
฿2,410.17
List Price:  ฿3,443.25
You save:  ฿1,033.08
₺2,423.71
List Price:  ₺3,462.60
You save:  ₺1,038.88
B$418.75
List Price:  B$598.25
You save:  B$179.49
R1,273.04
List Price:  R1,818.71
You save:  R545.66
Лв129.87
List Price:  Лв185.54
You save:  Лв55.66
₩97,732.12
List Price:  ₩139,623.30
You save:  ₩41,891.18
₪255.55
List Price:  ₪365.09
You save:  ₪109.53
₱4,110.61
List Price:  ₱5,872.56
You save:  ₱1,761.94
¥10,630.43
List Price:  ¥15,186.98
You save:  ¥4,556.55
MX$1,418.07
List Price:  MX$2,025.91
You save:  MX$607.83
QR254.36
List Price:  QR363.39
You save:  QR109.02
P953.37
List Price:  P1,362.02
You save:  P408.64
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,478.89
List Price:  E£4,970.06
You save:  E£1,491.16
ብር8,820.94
List Price:  ብር12,601.88
You save:  ብር3,780.94
Kz63,759.63
List Price:  Kz91,089.09
You save:  Kz27,329.46
CLP$68,404.72
List Price:  CLP$97,725.22
You save:  CLP$29,320.50
CN¥507.53
List Price:  CN¥725.08
You save:  CN¥217.54
RD$4,206.74
List Price:  RD$6,009.89
You save:  RD$1,803.14
DA9,351.13
List Price:  DA13,359.34
You save:  DA4,008.20
FJ$158.85
List Price:  FJ$226.94
You save:  FJ$68.09
Q538.41
List Price:  Q769.20
You save:  Q230.78
GY$14,600.65
List Price:  GY$20,858.96
You save:  GY$6,258.31
ISK kr9,615.92
List Price:  ISK kr13,737.62
You save:  ISK kr4,121.70
DH699.24
List Price:  DH998.96
You save:  DH299.72
L1,281.52
List Price:  L1,830.82
You save:  L549.30
ден4,084.06
List Price:  ден5,834.63
You save:  ден1,750.56
MOP$559.24
List Price:  MOP$798.95
You save:  MOP$239.71
N$1,266.15
List Price:  N$1,808.86
You save:  N$542.71
C$2,568.06
List Price:  C$3,668.81
You save:  C$1,100.75
रु9,427.87
List Price:  रु13,468.97
You save:  रु4,041.09
S/262.66
List Price:  S/375.25
You save:  S/112.58
K281.39
List Price:  K402.01
You save:  K120.61
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,903.42
List Price:  ZK2,719.29
You save:  ZK815.86
L330.70
List Price:  L472.45
You save:  L141.75
Kč1,679.39
List Price:  Kč2,399.23
You save:  Kč719.84
Ft27,552.80
List Price:  Ft39,362.83
You save:  Ft11,810.03
SEK kr765.72
List Price:  SEK kr1,093.94
You save:  SEK kr328.21
ARS$70,549.59
List Price:  ARS$100,789.45
You save:  ARS$30,239.85
Bs482.26
List Price:  Bs688.98
You save:  Bs206.71
COP$307,907.55
List Price:  COP$439,886.78
You save:  COP$131,979.23
₡35,643.95
List Price:  ₡50,922.11
You save:  ₡15,278.16
L1,765.02
List Price:  L2,521.57
You save:  L756.54
₲545,488.80
List Price:  ₲779,303.12
You save:  ₲233,814.31
$U2,997.83
List Price:  $U4,282.79
You save:  $U1,284.96
zł286.31
List Price:  zł409.03
You save:  zł122.72
Already have an account? Log In

Transcript

We're going to have a more comprehensive project. This time, we're going to have a look at this version JPS basics two. So this time we have provided more packages to organize better our code, we have one package comm that easy to catch courses. And when we expand this one, we're going to have course as the interface we saw this one before. This time we have public access modifier and we talked about the reason in the previous video, then we have graphed course, as mentioned in the comments, we could have placed the draft course in this package, but again just for the sake of simplicity, we have put all these course related classes in the same package as the course interface. So as you see we are going to have an interface course which is going to be implemented by graph course and why graph course class we are simply simulating a course which is just draft which should be just watched and edited by the admin of easy to catch calm and shouldn't be visible to the end users actually the courses which you be watched by the end users are going to make the published courses which as you've seen here, the polished course implements the same course interface.

And it's composed of not only a name, but also a lens, because it's finalized version. And now the user has the option to watch the video. And we have the play, which is going to be similar to the playing of this video. So the second package we have is going to be calm that easy to catch at libraries, which includes two other classes draft courses library, which is simply a list of all draft courses. And it has some simple methods for adding things to the library and for loading the library. This one, again, for the sake of simplicity has been hard coded, let's say at the time you're working on these draft courses, Android and Scala and they have not been finalized or published.

And then we have a simple player library, which is going to be simulating loading the library and for all the courses in the list is going to be playing those courses. And as you know, this class should have access to the other package. It should be able to Import draft course from the package calm that is the cached courses. There is also a published courses library in the same package. And in here, we're going to have a list of published courses. Again, we have ADD methods, we have load, again, hard coded, let's say and the time we have a Java course.

And we're going to be watched by users. And then we have another published course JavaScript. And the time if we play the library is going to be loading those two courses for the end user. And for all those courses, which have been published, is going to be playing then we go to our third package, which is called is to cache the tools dot play are in here we have an internal player and by internal player, like to have a class which simulates what we're going to have as admin. So the internal player is just a player for the admin is not for the end users. And by using this one, the admin of this website should be able to watch all the movies and let's say specially for the draft courses, he should be able to edit those courses.

So the admin through these Internal player class has access to all draft courses library and all publish courses library released and after you have constructed an internal player by calling the constructor, you would be able to call the play courses method to play all the courses in both draft and publish courses library and we have done the same thing in the month of May we have said make a new object and through that object called a play courses, this should be the version of the player use just my admin and that's why we named internal player and we have placed that one in this package comm that is the cash dot tools dot player the fourth and the last package we have in this project is called easy to cache that users dot tools dot player and here we're going to have a package which is containing the video player as one of the tools that the end user has access to.

So if we expand this one, we're going to have a user player class, which as you seen here has imported the published courses library and has been able to access the Publish courses list and And has been able to play all the courses in the Publish courses library. So now back to internal play or as you've seen here, if you're on the main method what we have in the output would be simulating playing all the videos not only the draft videos, but also all our published videos. The difference is there the draft videos are still draft so it's not finalized by the publish videos are finalized and they have been settled and as finalized length of the video. Now, the same would be in here If you choose to use your player, user player class has been able to create an object and play all the published courses and improve on these classes you've seen here the user has been able to watch the courses which have been published like Java and JavaScript in this case, but again, the bad thing in here as we have put those comments is that even on common these lines that nothing prevents the end user to access the draft courses list in the library of draft courses.

So if we're on the main method shows us that all the courses including graph and publish are going to be playful The End User which in general isn't a good thing, it's not desired because these are draft courses and it shouldn't be played for the end user before being published. If you have the draft courses library to have the package access, then neither the internal player nor the user player have access to that one. What we desire is that you like to have these draft courses library to be accessed by the internal player, and we want to be able to prevent the user player to access the draft courses library. By the way, if we want to improve our project to be more realistic, we should have designed our draft courses library using a single tone design pattern. And the reason is that we need to have just one instance of these draft courses library at any given time the same for publish courses library, we don't design these two classes to be single tone again, for the sake of simplicity and keeping everything as simple as possible.

But the good practice is that whatever class we have, like these libraries, which would like to have at most one instance of them at any given time, it's better to use them single tool which we haven't used but just put them in the comments so that you know what would be the best practice so back to our problem one might argue that what if we have separated these two classes into different packages so let's have a look at the third version which is JP ms basics three so I close all the files in here and we go to JPS basics three and this version we have added a new package we have the courses sub package as we had before and now we have split the libraries into two different packages common is the cash at libraries dot draft, which has just one class which is going to be graph courses library and comm that is it the cache of libraries are published which is now containing published courses library the other packages and classes remain the same.

But as you see in here, it doesn't solve the problem because anyways, we have declared the graph courses library to be of public access anyways in order to be accessed by the internal player but if we do so, We have done, it would be not only accessible by the internal player, but also would be accessible by the user player as well. So if you uncomment these lines again, the same problem, nothing prevents the end user to import a draft courses library class and then make a reference to that wall and create a new object and then using that one, play the courses, even the draft ones. So as you see, the problem is very clear. You're going to have some kind of access modifier in the level of packages not at the level of classes, we like to have some kind of mechanism so that this draft package will be only accessible by the player package.

And we'd like to have some kind of mechanism to prevent this package to be used or imported by this package which should be accessible just to the end user. This will be a key point to have a look at what Java nine has to offer using is jpm s

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.