Usuário:Dago
De WikiLICC
Dagoberto Adriano Rizzotto Justo, Prof.
Esta é a página Wiki do Dago.
Índice
Disciplinas
Grupo de Pesquisa em Análise Numérica
- Linha de Pesquisa
- Análise Numérica
- Pesquisa em Análise Numérica
<source lang="fortran">
module m_strategy_pattern
implicit none
abstract interface
!! A generic interface to a subroutine accepting array of integers subroutine generic_function(numbers) integer, dimension(:), intent(in) :: numbers end subroutine
end interface
type :: Button
character(len=20) :: label procedure(generic_function), pointer, nopass :: on_submit
contains
procedure :: init
end type Button
contains
subroutine init(self, func, label) class(Button), intent(inout) :: self procedure(generic_function) :: func character(len=*) :: label self%on_submit => func !! Procedure pointer self%label = label end subroutine init
subroutine summation(array) integer, dimension(:), intent(in) :: array integer :: total total = sum(array) write(*,*) total end subroutine summation
subroutine join(array) integer, dimension(:), intent(in) :: array write(*,*) array !! Just write out the whole array end subroutine join
end module m_strategy_pattern
!! The following program demonstrates the usage of the module program test_strategy use m_strategy_pattern implicit none
type(Button) :: button1, button2 integer :: i
call button1%init(summation, "Add them") call button2%init(join, "Join them")
call button1%on_submit([(i, i=1,10)]) !! Displays 55 call button2%on_submit([(i, i=1,10)]) !! Prints out the array
end program test_strategy </source>
Referências
Ver também
- Visual
- Dago:Links: Página de Links externos.
- Dago:Testes: Página de Testes Wiki.
- Dago:oc: Testes com o ocPortal.
- http://www.oodesign.com/
- http://software.intel.com/en-us/articles/intel-guide-for-developing-multithreaded-applications/