Skip to content

Commit

Permalink
deploy: 7343905
Browse files Browse the repository at this point in the history
  • Loading branch information
zoziha committed Jul 25, 2024
1 parent 2879284 commit 79f7a45
Show file tree
Hide file tree
Showing 27 changed files with 2,154 additions and 2,154 deletions.
6 changes: 3 additions & 3 deletions Introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h2 id="设计模式列表"><a class="header" href="#设计模式列表">设计
<table><thead><tr><th align="center">状态</th><th align="center">创建型模式</th><th align="center">结构型模式</th><th align="center">行为模式</th></tr></thead><tbody>
<tr><td align="center">完成</td><td align="center">抽象工厂、生成器、工厂方法、原型、单例。</td><td align="center">适配器、桥接、组合、装饰、外观、代理、享元。</td><td align="center">责任链、命令、迭代器、观察者、状态、模板方法、备忘录、中介者、访问者、策略。</td></tr>
</tbody></table>
<h4 id="创建型模式"><a class="header" href="#创建型模式">创建型模式</a></h4>
<h3 id="创建型模式"><a class="header" href="#创建型模式">创建型模式</a></h3>
<ul>
<li><input disabled="" type="checkbox" checked=""/>
抽象工厂</li>
Expand All @@ -173,7 +173,7 @@ <h4 id="创建型模式"><a class="header" href="#创建型模式">创建型模
<li><input disabled="" type="checkbox" checked=""/>
单例</li>
</ul>
<h4 id="结构型模式"><a class="header" href="#结构型模式">结构型模式</a></h4>
<h3 id="结构型模式"><a class="header" href="#结构型模式">结构型模式</a></h3>
<ul>
<li><input disabled="" type="checkbox" checked=""/>
适配器</li>
Expand All @@ -190,7 +190,7 @@ <h4 id="结构型模式"><a class="header" href="#结构型模式">结构型模
<li><input disabled="" type="checkbox" checked=""/>
代理</li>
</ul>
<h4 id="行为模式"><a class="header" href="#行为模式">行为模式</a></h4>
<h3 id="行为模式"><a class="header" href="#行为模式">行为模式</a></h3>
<ul>
<li><input disabled="" type="checkbox" checked=""/>
责任链</li>
Expand Down
140 changes: 70 additions & 70 deletions behavioral/chain-of-responsibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,68 +167,68 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>
implicit none
private

public :: patient, department, reception, doctor, medical, cashier
public :: patient_type, department_type, reception_type, doctor_type, medical_type, cashier_type

type patient
type patient_type
character(:), allocatable :: name
logical :: registration_done
logical :: doctor_check_up_done
logical :: medicine_done
logical :: payment_done
end type patient
end type patient_type

type, abstract :: department
type, abstract :: department_type
contains
procedure(execute_procedure), deferred :: execute
procedure(set_next_procedure), deferred :: set_next
end type department
end type department_type

abstract interface
subroutine execute_procedure(self, p)
import department, patient
class(department), intent(inout) :: self
type(patient), intent(inout) :: p
import department_type, patient_type
class(department_type), intent(inout) :: self
type(patient_type), intent(inout) :: p
end subroutine execute_procedure
subroutine set_next_procedure(self, next)
import department
class(department), intent(inout) :: self
class(department), intent(inout) :: next
import department_type
class(department_type), intent(inout) :: self
class(department_type), intent(inout) :: next
end subroutine set_next_procedure
end interface

type, extends(department) :: reception
class(department), pointer :: next
type, extends(department_type) :: reception_type
class(department_type), pointer :: next
contains
procedure :: execute =&gt; reception_execute
procedure :: set_next =&gt; reception_set_next
end type reception
procedure :: execute =&gt; reception_type_execute
procedure :: set_next =&gt; reception_type_set_next
end type reception_type

type, extends(department) :: doctor
class(department), pointer :: next
type, extends(department_type) :: doctor_type
class(department_type), pointer :: next
contains
procedure :: execute =&gt; doctor_execute
procedure :: set_next =&gt; doctor_set_next
end type doctor
procedure :: execute =&gt; doctor_type_execute
procedure :: set_next =&gt; doctor_type_set_next
end type doctor_type

type, extends(department) :: medical
class(department), pointer :: next
type, extends(department_type) :: medical_type
class(department_type), pointer :: next
contains
procedure :: execute =&gt; medicine_execute
procedure :: set_next =&gt; medicine_set_next
end type medical
procedure :: execute =&gt; medicine_type_execute
procedure :: set_next =&gt; medicine_type_set_next
end type medical_type

type, extends(department) :: cashier
class(department), pointer :: next
type, extends(department_type) :: cashier_type
class(department_type), pointer :: next
contains
procedure :: execute =&gt; cashier_execute
procedure :: set_next =&gt; cashier_set_next
end type cashier
procedure :: execute =&gt; cashier_type_execute
procedure :: set_next =&gt; cashier_type_set_next
end type cashier_type

contains

subroutine reception_execute(self, p)
class(reception), intent(inout) :: self
type(patient), intent(inout) :: p
subroutine reception_type_execute(self, p)
class(reception_type), intent(inout) :: self
type(patient_type), intent(inout) :: p

if (p%registration_done) then
print *, &quot;Patient registration already done.✔️&quot;
Expand All @@ -240,19 +240,19 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>
p%registration_done = .true.
call self%next%execute(p)

end subroutine reception_execute
end subroutine reception_type_execute

subroutine reception_set_next(self, next)
class(reception), intent(inout) :: self
class(department), intent(inout) :: next
subroutine reception_type_set_next(self, next)
class(reception_type), intent(inout) :: self
class(department_type), intent(inout) :: next

allocate (self%next, source=next)

end subroutine reception_set_next
end subroutine reception_type_set_next

subroutine doctor_execute(self, p)
class(doctor), intent(inout) :: self
type(patient), intent(inout) :: p
subroutine doctor_type_execute(self, p)
class(doctor_type), intent(inout) :: self
type(patient_type), intent(inout) :: p

if (p%doctor_check_up_done) then
print *, &quot;Doctor checkup already done.✔️&quot;
Expand All @@ -264,19 +264,19 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>
p%doctor_check_up_done = .true.
call self%next%execute(p)

end subroutine doctor_execute
end subroutine doctor_type_execute

subroutine doctor_set_next(self, next)
class(doctor), intent(inout) :: self
class(department), intent(inout) :: next
subroutine doctor_type_set_next(self, next)
class(doctor_type), intent(inout) :: self
class(department_type), intent(inout) :: next

allocate (self%next, source=next)

end subroutine doctor_set_next
end subroutine doctor_type_set_next

subroutine medicine_execute(self, p)
class(medical), intent(inout) :: self
type(patient), intent(inout) :: p
subroutine medicine_type_execute(self, p)
class(medical_type), intent(inout) :: self
type(patient_type), intent(inout) :: p

if (p%medicine_done) then
print *, &quot;Medicine already given to patient.✔️&quot;
Expand All @@ -288,19 +288,19 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>
p%medicine_done = .true.
call self%next%execute(p)

end subroutine medicine_execute
end subroutine medicine_type_execute

subroutine medicine_set_next(self, next)
class(medical), intent(inout) :: self
class(department), intent(inout) :: next
subroutine medicine_type_set_next(self, next)
class(medical_type), intent(inout) :: self
class(department_type), intent(inout) :: next

allocate (self%next, source=next)

end subroutine medicine_set_next
end subroutine medicine_type_set_next

subroutine cashier_execute(self, p)
class(cashier), intent(inout) :: self
type(patient), intent(inout) :: p
subroutine cashier_type_execute(self, p)
class(cashier_type), intent(inout) :: self
type(patient_type), intent(inout) :: p

if (p%payment_done) then
print *, &quot;Payment Done.✔️&quot;
Expand All @@ -310,15 +310,15 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>
print *, &quot;Cashier getting money from patient.&quot;
p%payment_done = .true.

end subroutine cashier_execute
end subroutine cashier_type_execute

subroutine cashier_set_next(self, next)
class(cashier), intent(inout) :: self
class(department), intent(inout) :: next
subroutine cashier_type_set_next(self, next)
class(cashier_type), intent(inout) :: self
class(department_type), intent(inout) :: next

allocate (self%next, source=next)

end subroutine cashier_set_next
end subroutine cashier_type_set_next

end module hospital_CoR
</code></pre>
Expand All @@ -328,24 +328,24 @@ <h2 id="示例"><a class="header" href="#示例">示例</a></h2>

use hospital_CoR

type(cashier) :: c
type(medical) :: m
type(doctor) :: d
type(reception) :: r
type(cashier_type) :: c
type(medical_type) :: m
type(doctor_type) :: d
type(reception_type) :: r

type(patient) :: p1, p2
type(patient_type) :: p1, p2

!&gt; Set next for departments
call m%set_next(c)
call d%set_next(m)
call r%set_next(d)

p1 = patient(&quot;abc&quot;, .true., .true., .true., .true.)
p1 = patient_type(&quot;abc&quot;, .true., .true., .true., .true.)
!&gt; Patient visiting
print *, &quot;&gt; Patient `&quot;//p1%name//&quot;` : &quot;
call r%execute(p1)

p2 = patient(&quot;def&quot;, .true., .false., .false., .false.)
p2 = patient_type(&quot;def&quot;, .true., .false., .false., .false.)
!&gt; Patient visiting
print *, &quot;&gt; Patient `&quot;//p2%name//&quot;` : &quot;
call r%execute(p2)
Expand Down
Loading

0 comments on commit 79f7a45

Please sign in to comment.