Referencing symbols from the parent module

If the sub-module needs access to any symbol from the parent module, then the sub-module may use the import or using statement while adding .. as a prefix to the name of the parent module. This is shown with the following code:

# Mortgage.jl
module Mortgage

# access to parent module's variable
using ..Calculator: days_per_year

end # module

Now, the Mortgage sub-module has access to the days_per_year constant from the parent module. 

Having the ability to reference symbols and functions between modules and sub-modules allows us to just reorganize code into various sub-modules and keep it working as before. However, the reason for separating code into sub-modules in the first place is to allow the developer to work in each module independently. In addition, having bidirectional references could lead to confusion and messy spaghetti code.

Next, we will discuss how to reduce such coupling among modules and sub-modules.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.205.154