-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[book] | ||
authors = ["左志华"] | ||
authors = ["ZUO Zhihua"] | ||
language = "zh" | ||
multilingual = false | ||
src = "src" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
program interface_limit_main | ||
|
||
use interface_limit_module, only: circle, square, cs_interact | ||
implicit none | ||
type(circle) :: c1 | ||
type(square) :: s1 | ||
|
||
call cs_interact(c1, s1) | ||
|
||
end program interface_limit_main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
!> @note Because fortran's interfaces are static, it is difficult to implement dynamic binding, | ||
!> which restricts abstract classes from being fully functional or interacting with each other in a way that is not flexible; | ||
!> instead, it would be more practical to use non-procedural binding. | ||
module interface_limit_module | ||
|
||
implicit none | ||
|
||
private | ||
public :: circle, square, shape, cs_interact | ||
|
||
type, abstract :: shape | ||
end type shape | ||
|
||
abstract interface | ||
subroutine interact(shape1, shape2) | ||
import :: shape | ||
class(shape), intent(inout) :: shape1, shape2 | ||
end subroutine interact | ||
end interface | ||
|
||
type, extends(shape) :: circle | ||
end type circle | ||
|
||
type, extends(shape) :: square | ||
end type square | ||
|
||
contains | ||
|
||
!> @note This is a non-procedural binding, which is more flexible than procedural binding when it have to comes to dynamic binding. | ||
subroutine cs_interact(cir, squ) | ||
type(circle), intent(inout) :: cir | ||
type(square), intent(inout) :: squ | ||
|
||
print *, "circle-square interaction" | ||
|
||
end subroutine cs_interact | ||
|
||
end module interface_limit_module |