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
€64.99
List Price:  €92.85
You save:  €27.85
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$105.96
List Price:  A$151.38
You save:  A$45.42
S$94.48
List Price:  S$134.98
You save:  S$40.50
HK$546.78
List Price:  HK$781.15
You save:  HK$234.36
CHF 63.33
List Price:  CHF 90.48
You save:  CHF 27.14
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.44
List Price:  NZ$166.35
You save:  NZ$49.91
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,492.21
List Price:  ₨27,847.21
You save:  ₨8,355
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$355.02
List Price:  B$507.19
You save:  B$152.17
R1,295.44
List Price:  R1,850.71
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪260.15
List Price:  ₪371.66
You save:  ₪111.51
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,713.01
List Price:  ¥15,304.96
You save:  ¥4,591.95
MX$1,187.73
List Price:  MX$1,696.83
You save:  MX$509.10
QR254.83
List Price:  QR364.06
You save:  QR109.23
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.65
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,773.40
List Price:  ISK kr13,962.60
You save:  ISK kr4,189.20
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.26
List Price:  ден5,712.05
You save:  ден1,713.78
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.01
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,334.28
List Price:  Ft36,193.38
You save:  Ft10,859.10
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
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.