I have already discussed many theoretical concepts about “Java 9 Module System” and also developed couple of examples using CMD prompt and IDEs in my previous posts.Now I’m going to discuss about “How to Develop and Test Implied Readability Between Modules With IntelliJ IDEA IDE” in this post.

我已经讨论了许多有关“ Java 9模块系统”的理论概念,并且在以前的文章中还使用CMD提示和IDE开发了一些示例。现在,我将讨论“如何使用IntelliJ开发和测试模块之间的隐式可读性”。这篇文章中的“ IDEA IDE”。

In this series of “Java 9 Module System” posts, it is my fifth post. Before reading this post, please go through my previous post by clicking the following links to understand some basics about Java 9 Modules.

在“ Java 9模块系统”系列文章中,这是我的第五篇文章。 在阅读本文之前,请单击以下链接以浏览我的上一篇文章,以了解有关Java 9 Modules的一些基础知识。

  • Introduction to Java 9 Module SystemJava 9模块系统简介
  • Java 9 Module and Module Descriptor BasicsJava 9模块和模块描述符基础知识
  • Java 9 HelloWorld Module with CMD Prompt带有CMD提示的Java 9 HelloWorld模块
  • Java 9 HelloWorld Module with Eclipse and IntelliJ IDEs带有Eclipse和IntelliJ IDE的Java 9 HelloWorld模块

发表简要目录: (Post Brief Table of Content:)

  • What is Readability?什么是可读性?
  • What is Accessibility?什么是辅助功能?
  • What is Implied Readability?什么是隐含可读性?
  • Develop Module Dependency With Bad Approach用错误的方法开发模块依赖性
  • Test Module Dependency For Bad Approach测试模块对不良方法的依赖性
  • Develop Implied Readability(Good Approach)开发隐含的可读性(好的方法)
  • Advantages of Implied Readability隐含可读性的优点

什么是可读性? (What is Readability?)

If Module-1 directly depends on Module-2, then it is know as “Module-1 Reads Module-2”. In other words, we can say that “Module-2 is Readable by Module-1”.

如果模块1直接依赖于模块2,则称为“模块1读取模块2”。 换句话说,我们可以说“模块2可以被模块1读取”。

So, It is know as Readability relationship between Module-1 and Module-2. Let us explore it with some JDK 9 Modules using below diagram.

因此,称为模块1和模块2之间的可读性关系。 让我们使用下图通过一些JDK 9模块进行探索。

Here “java.sql” module reads “java.xml”, “java.base” and “java.logging” modules.

在这里,“ java.sql”模块读取“ java.xml”,“ java.base”和“ java.logging”模块。

什么是辅助功能? (What is Accessibility?)

If Module-1 has Readability Relationship with Module-2, then Module-1 can “Access” all Public API of Module-2. It is know as Accessibility Relationship between those two modules. As we discussed in my previous posts, a Module can have only Public API or both Public and Private API.

如果模块1与模块2具有可读性关系,则模块1可以“访问”模块2的所有公共API。 这就是这两个模块之间的可访问性关系。 正如我们在之前的文章中所讨论的,模块只能具有公共API或公共和私有API。

In simple words, Public API means Public Types. If you don’t understand it well, We will discuss on “How to develop Public and Private API” in my coming posts.

简而言之,Public API表示公共类型。 如果您不太了解,我们将在我的后续文章中讨论“如何开发公共和私有API”。

Both Readability and Accessibility concepts are the basis for achieving the two main Goals of Java 9 Module System:

可读性和可访问性概念都是实现Java 9 Module System的两个主要目标的基础:

  • Reliable Configuration可靠的配置
  • Strong Encapsulation强封装

We can define Readability and Accessibility Relationships between modules using the following concepts:

我们可以使用以下概念定义模块之间的可读性和可访问性关系:

  • exports clause出口条款
  • requires clause要求条款
  • public modifier公共修饰语
  • to clause到条款

We will discuss all these concepts in this post with examples except last one (check for my coming posts).

我们将在本文中讨论所有这些概念,并附上最后一个例子(请检查我的后续文章)。

什么是隐含可读性? (What is Implied Readability?)

If Module-1 reads on Module-2 and Module-2 reads on Module-3, then Module-1 reads Module-3. This kinds of Transitive Dependency is known as “Implied Readability” from Moudle-3 to Module-1.

如果模块1读取模块2,而模块2读取模块3,则模块1读取模块3。 这种传递依赖性从Moudle-3到Module-1被称为“隐含可读性”。

It is also known as Implied Dependency.

也称为隐含依赖关系。

Suppose if we have relationship between three modules as shown in the below diagram.

假设我们在三个模块之间具有关系,如下图所示。

“LastName” Module depends on “FirstName”, “FullName” Module depends on Both Modules : “FirstName” and “LastName”. That means there is a Transitive Dependency between these three modules:
FullName ==> LastName ==> FirstName

“ LastName”模块取决于“ FirstName”,“ FullName”模块取决于两个模块:“ FirstName”和“ LastName”。 这意味着这三个模块之间存在传递依赖关系:
FullName ==> LastName ==> FirstName

In Java 9 Module System, We have two approaches to resolve these Module Dependencies.
1. Bad Approach
This approach solves Transitive Dependency between modules without using “Implied Readability”.

在Java 9 Module System中,我们有两种方法来解决这些模块依赖性。
1.错误的方法
这种方法无需使用“隐式可读性”即可解决模块之间的传递依赖性。

Here “FullName” imports both modules using “requires” clauses as shown below:

这里,“ FullName”使用“ requires”子句导入两个模块,如下所示:

module FirstName{ exorts FirstName;
}
module LastName{requires FirstName;exports LastName;
}
module FullName{requires FirstName;requires LastName;exports FullName;
}

It is bad approach because LastName is already importing FirstName Module then why don’t we get that import feature to FullName Module?? Instead of using that, FullName is importing both modules. It works perfectly, however it’s not a recommended approach.

这是一种不好的方法,因为LastName已经在导入FirstName模块,那么为什么我们不将该导入功能导入FullName Module? FullName而不是使用它,而是导入两个模块。 它可以完美运行,但是不建议这样做。

In real-time projects, we will have this kind of dependencies on many modules, is it good to import all modules?? Definitely NO, right.

在实时项目中,我们将在许多模块上具有这种依赖关系,是否可以导入所有模块? 绝对不行,对。

2. Good Approach
This approach solves Transitive Dependency between modules using “Implied Readability” Technique.

2.好的方法
这种方法使用“隐含可读性”技术解决了模块之间的传递依赖性。

Here “FullName” imports only LastName module using “requires” clause, but it gets “FirstName” automatically without importing it as shown below:

在这里,“ FullName”仅使用“ requires”子句导入LastName模块,但它会自动获取“ FirstName”,而不会如下所示导入:

module FirstName{ exorts FirstName;
}
module LastName{requires public FirstName;exports LastName;
}
module FullName{requires LastName;exports FullName;
}

This good approach is also know as “Implied Readability” in Java 9 Module System. So we can implement “Implied Readability” using “public” modifier as shown in the above example.

这种好的方法在Java 9 Module System中也称为“隐式可读性”。 因此,我们可以使用“ public”修饰符实现“隐式可读性”,如上例所示。

We will develop both approaches in the coming sections to understand it well.

我们将在接下来的部分中开发两种方法,以使其更好地理解。

Please go through this post Java 9 HelloWorld Module with Eclipse and IntelliJ IDEs to know on “How to develop Java 9 Modules using IntelliJ IDE”.

请仔细阅读这篇带有Eclipse和IntelliJ IDE的Java 9 HelloWorld模块,以了解“如何使用IntelliJ IDE开发Java 9模块”。

制定错误的方法 (Develop Bad Approach)

In this section we will develop bad approach to solve this Transitive Dependency without using “Implied Readability”. Once we are comfortable with this approach, we will develop right approach in the coming sections.

在本节中,我们将开发不使用“隐式可读性”来解决此传递依赖关系的错误方法。 一旦对这种方法感到满意,我们将在接下来的部分中开发正确的方法。

Let us understand this approach with this digarm:

让我们通过以下摘要了解这种方法:

  • Create an IntelliJ IDEA Project创建一个IntelliJ IDEA项目
  • Project Name: ImpliedDependency

    项目名称:隐式依赖

  • Develop FirstName Module Code开发名字模块代码
    • Create FirstName Module创建名字模块
    • Module Name: : com.firstname

      模块名称:com.firstname

    • Create FirstName Module Package创建名字模块包
    • Package name: com.firstname.name

      套件名称:com.firstname.name

    • Create Java Component(s)创建Java组件
    • FirstName.java

      名字.java

package com.firstname.name;public class FirstName {public String getFirstName() {// Some logic to get FirstNamereturn "FName";}
}
  • Create FirstName Module Descriptor创建名字模块描述符
  • module-info.java

    module-info.java

    module com.firstname {exports com.firstname.name;}
  • Develop LastName Module Code开发姓氏模块代码
    • Create LastName Module创建姓氏模块
    • Module Name: : com.lastname

      模块名称:: com.lastname

    • Create LastName Module Package创建姓氏模块包
    • Package name: com.lastname.name

      套件名称:com.lastname.name

    • Create Java Component(s)创建Java组件
    • LastName.java

      LastName.java

    package com.lastname.name;public class LastName {public String getLastName() {// Some logic to get LastName return "LName";}
    }

    Name.java

    名称.java

    package com.lastname.name;import com.firstname.name.FirstName;public class Name {public String getName() {FirstName fname = new FirstName();LastName  lname = new LastName();return fname.getFirstName() + " " + lname.getLastName();}}
  • Create LastName Module Descriptor创建姓氏模块描述符
  • module-info.java

    module-info.java

    module com.lastname {requires com.firstname;exports com.lastname.name;}

    As this module is dependent on FirstName Module, we should add “requires” clause to that module as shown in the above example.

    由于此模块依赖于FirstName模块,因此我们应该在该模块中添加“ requires”子句,如上面的示例所示。

  • Develop FullName Module Code开发全名模块代码
    • Create FullName Module创建全名模块
    • Module Name: : com.fullname

      模块名称:com.fullname

    • Create FullName Module Package创建全名模块包
    • Package name: com.fullname.name

      套件名称:com.fullname.name

    • Create Java Component(s)创建Java组件
    • MiddleName.java

      MiddleName.java

    package com.fullname.name;public class MiddleName {public String getMiddleName() {// Some logic to get MiddleNamereturn "MName";}
    }

    FullName.java

    FullName.java

    package com.fullname.name;import com.firstname.name.FirstName;
    import com.lastname.name.LastName;public class FullName {public String getFullName() {FirstName  fname = new FirstName();MiddleName mname = new MiddleName();LastName   lname = new LastName();return fname.getFirstName() + " " + mname.getMiddleName()  + " " + lname.getLastName();}
    }
  • Create FullName Module Descriptor创建全名模块描述符
  • module-info.java

    module-info.java

    module com.fullname {requires com.firstname;requires com.lastname;exports com.fullname.name;}

    As this module is dependent on FirstName and LastName Modules, we should add requires clauses to both of them as shown in the above example.

    由于此模块依赖于FirstName和LastName模块,因此我们应该在这两个模块上添加require子句,如上例所示。

    开发测试模块和测试不良方法 (Develop Test Module and Test Bad Approach)

    In this section, we will develop a Test Module to test this Bad Approach.

    在本节中,我们将开发一个测试模块来测试这种不良方法。

    • Create Test Module创建测试模块
    • Module Name: : com.name.test

      模块名称:com.name.test

    • Create Test Module Package创建测试模块包
    • Package name: com.name.test

      套件名称:com.name.test

    • Create Java Component(s)创建Java组件
    • NameTester.java

      NameTester.java

    package com.name.test;import com.fullname.name.FullName;public class NameTester {public static void main(String a[]){FullName fullName = new FullName();System.out.println("Name = " + fullName.getFullName());}}
  • Final Project looks like below.最终项目如下所示。
  • Run the NameTester class运行NameTester类
  • Output:-

    输出:-

    Name = FName MName LName

    It works perfectly, however it is not a recommended approach. Let us develop same application using “Implied Readability” Technique.

    它可以完美运行,但是不建议这样做。 让我们使用“隐含可读性”技术开发相同的应用程序。

    开发和测试隐含依赖性 (Develop and Test Implied Dependency)

    • Please follow same steps as we did for Bad approach.请按照与不良方法相同的步骤进行操作。
    • Change “LastName” Module Descriptor更改“姓氏”模块描述符
    • module-info.java

      module-info.java

    module com.lastname {requires public com.firstname;exports com.lastname.name;}

    Here we can observe that “public” modifier before Module name. When we use this in requires clause as shown in the above Module Descriptor, that means any Module which reads this “LastName” Module can also reads “FirstName” Module automatically. No need to use extra “requires” clause.

    在这里,我们可以看到模块名称之前的“ public”修饰符。 当我们在上面的模块描述符中显示的require子句中使用此模块时,这意味着任何读取此“ LastName”模块的模块也可以自动读取“ FirstName”模块。 无需使用额外的“ requires”子句。

  • Change “FullName” Module Descriptor更改“全名”模块描述符
  • module-info.java

    module-info.java

    module com.fullname {requires com.lastname;exports com.fullname.name;}

    Here we are not using extra “requires” clause for “FirstName” Module. Still, it can reads that module because of “LastName” Module’s “Implied Readability” Technique.

    在这里,我们不在“ FirstName”模块上使用额外的“ requires”子句。 尽管如此,由于“姓氏”模块的“隐含可读性”技术,它仍可以读取该模块。

  • Use same Tester module to test this application.使用相同的测试器模块来测试此应用程序。
  • Same output for this application too.

    此应用程序的输出也相同。

    NOTE:-
    Here we are using just few modules. However, it is not the same case in Real-time projects. A Real-time Module may depend on more Modules and it is not the right approach to import all of them. Am I right??

    注意:-
    在这里,我们仅使用几个模块。 但是,在实时项目中情况并非如此。 实时模块可能依赖于更多模块,并且导入所有模块都不是正确的方法。 我对吗??

    几点要记住的要点 (Few Important Points to Remember)

    In this section, we will briefly discuss about some important points to remember about Java 9 Module System.

    在本节中,我们将简要讨论一些有关Java 9 Module System的重要注意事项。

    • Every Module, by definition reads itself.根据定义,每个模块都会读取自身。
    • Java 9 Module System does NOT supoort Cyclic Graphs that means it supports only Acyclic Graphs.Java 9模块系统不支持循环图,这意味着它仅支持非循环图。
    • Two or more Modules may have same package names. That means we can use same package names in two different Modules.两个或多个模块可能具有相同的程序包名称。 这意味着我们可以在两个不同的模块中使用相同的软件包名称。
    • By default, all Java 9 Modules (JDK Modules or User Define Modules) depends on “java.base” Module.默认情况下,所有Java 9模块(JDK模块或用户定义模块)都依赖于“ java.base”模块。

    That’s it all about “Develop and Test Implied Dependency With Eclipse IDE” topic. We will discuss some more concepts about Java SE 9 Modules Development in my coming posts.

    这就是“使用Eclipse IDE开发和测试隐式依赖关系”主题的全部内容。 在我的后续文章中,我们将讨论有关Java SE 9 Modules Development的更多概念。

    Please drop me a comment if you like my post or have any issues/suggestions/type errors.

    如果您喜欢我的帖子或有任何问题/建议/类型错误,请给我评论。

    Thank you for reading my tutorials.

    感谢您阅读我的教程。

    Happy Java SE 9 Learning!

    Java SE 9学习愉快!

    翻译自: https://www.journaldev.com/13632/javase9-implied-readability-part5

Java SE 9:使用IntelliJ IDE开发和测试模块之间的隐式可读性(第5部分)相关推荐

  1. Java SE 9:使用Eclipse和IntelliJ IDEA IDE开发和测试HelloWorld模块(第4部分)

    I have already discuss about "Java Module System" Basics in my previous posts. I'm going t ...

  2. mule esb java实例_基于AnypointStudio IDE开发MuleESB实例

    基于AnypointStudio IDE开发MuleESB实例 本文部分内容引用https://www.cnblogs.com/enjoyingsoft/p/10132360.html,在此,对原著作 ...

  3. java se系列(一)开发前奏

    1. 软硬件知识 电子计算机:俗称电脑,是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备.由硬件和软件所组成,没有安装任何软件的计算机称为裸机 cpu:是一台计算机的运算核心和控制核 ...

  4. 安卓开发-Activity的显示意图和隐式意图+实例+Activity界面间数据的传递实例

    <一:显示意图和隐式意图> 1.显示意图 //想打开的页面需要在创建意图时显式指定要打开那个Activity Intent intent = new Intent(this, 指定Acti ...

  5. 超全IntelliJ IDE开发指南,更有更改炫酷背景,字体教程!

    作者:氷泠 链接:https://zhuanlan.zhihu.com/p/136346657 来源:知乎 1 概述 IDEA全称IntelliJ IDEA,主要用于Java开发的IDE,代码自动提示 ...

  6. 小饶学编程之JAVA SE第二部分——MySql 数据库 开发:04Properties

    Properties 一.Properties 二.使用 三.JAVA和properties文件的交互 3.1 数据的读取 3.2 数据的存储 3.3 扩展 四. 案例 一.Properties ​P ...

  7. java se项目实战视频_项目整体测试_09-JAVASE项目实战-电影管理系统_Java视频-51CTO学院...

    基础篇https://edu.51cto.com/course/19845.html https://edu.51cto.com/course/19845.html https://edu.51cto ...

  8. java开发和测试的不同_一些基础的面试的java知识,普及下。开发和测试都用得到。...

    直接看代码吧. package gdk.ware; import java.text.SimpleDateFormat; import java.util.Date; import java.util ...

  9. AndroidStudio安卓原生开发_Activity的启动方法_隐式启动2种方法_activity关闭---Android原生开发工作笔记83

    暂时不写内容,后边补上,因为工作太忙,先把图,以及重要的难点说明写出来,后边会修改成详细的文章

最新文章

  1. ios 项目的.gitignore
  2. String、StringBuffer、StringBuilder介绍
  3. 成功解决''g++' 不是内部或外部命令,也不是可运行的程序 或批处理文件
  4. 亮度均匀性 matlab,求:亮度保持的夜景图像直方图均衡算法 matlab程序
  5. NEC SV8100电话交换机配置梓博电话计费系统
  6. android实现qq修改密码底部弹出框_易查分强大的“可修改列”功能:轻松实现填表、留言和信息核对...
  7. 判断字符串是否是有效的手机号码
  8. 基于MyEclipse+Mysql+Tomcat+SSH开发的运动会管理系统
  9. Android Studio查看Android源码
  10. POI实现word转html(带图片),实现word在线预览
  11. 怎么用imp命令把dmp文件从本地导入到远处的数据库服务器,Oracle 数据库导入导出dmp文件...
  12. 【个人博客网页模板】
  13. 判断一个数是否为素数
  14. 双击我的计算机打不开,电脑我的计算机双击打不开怎么办
  15. caffe中各种cblas的函数使用总结
  16. 基于GMM模型的图像分割与颜色迁移算法
  17. SQL server 添加、修改、删除字段
  18. 模型推理加速系列|如何用ONNX加速BERT特征抽取(附代码)
  19. mac电脑忘记账户名密码解决方法
  20. XML fragments parsed from previous mappers does not contain values

热门文章

  1. Alarm:IT界朋友请珍惜你的身体[转贴]
  2. [转载] Python time sleep()方法如何使用?
  3. [转载] Python pep8编码规范
  4. zabbix--基础概念及原理
  5. bzoj千题计划269:bzoj2655: calc (拉格朗日插值)
  6. 环境变量 - Maven
  7. 【SSH】 之 Struts2
  8. windows下如何使用QT编写dll程序 .
  9. javacript 验证函数
  10. 2.2 Mnist手写数据集