Skip to content

Commit

Permalink
add interface-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zoziha committed Aug 4, 2023
1 parent ee88eb5 commit da3b70d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2021~2022, 左志华
Copyright (c) 2021~2022, ZUO Zhihua
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
[![BSD-3](https://img.shields.io/github/license/zoziha/Fortran-Design-Patterns?color=pink)](LICENSE)
[![fpm](https://github.com/zoziha/Fortran-Design-Patterns/workflows/fpm/badge.svg)](https://github.com/zoziha/Fortran-Design-Patterns/actions)
[![mdbook](https://github.com/zoziha/Fortran-Design-Patterns/workflows/mdbook/badge.svg)](https://github.com/zoziha/Fortran-Design-Patterns/actions)
[![wakatime](https://wakatime.com/badge/user/ca8e3153-da86-47e8-ba89-1fac0c842c19.svg)](https://wakatime.com/@ca8e3153-da86-47e8-ba89-1fac0c842c19)

《Fortran的23种设计模式》是一份Fortran面向对象编程中文实用教程。

|项目|描述|
|:-:|:-:|
|版本:|0.1.0|
|作者:|左志华(zoziha)|
|版本:|0.2.0|
|作者:|ZUO Zhihua|
|网页:|https://zoziha.github.io/Fortran-Design-Patterns/|
|版权:|Copyright (c) 2021~2022 zoziha|
|版权:|Copyright (c) 2021~2023 zoziha|

## 开始

Expand Down
2 changes: 1 addition & 1 deletion doc/book.toml
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"
Expand Down
14 changes: 10 additions & 4 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name = "Fortran-Design-Patterns"
version = "0.1.1"
version = "0.2.0"
license = "BSD-3"
maintainer = "左志华"
copyright = "Copyright 2021 左志华"
maintainer = "ZUO Zhihua"
copyright = "Copyright 2021~2023 ZUO Zhihua"
description = "Fortran Design Patterns"
categories = ["Demo", "OOP", "Modern Fortran"]

Expand Down Expand Up @@ -129,4 +129,10 @@ main = "proxy_main.f90"
[[test]]
name = "wrapper"
source-dir = "src/structural/wrapper"
main = "wrapper_main.f90"
main = "wrapper_main.f90"

# interface-limit
[[test]]
name = "interface-limit"
source-dir = "src/interface-limit"
main = "interface_limit_main.f90"
10 changes: 10 additions & 0 deletions src/interface-limit/interface_limit_main.f90
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
38 changes: 38 additions & 0 deletions src/interface-limit/interface_limit_module.f90
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

0 comments on commit da3b70d

Please sign in to comment.