<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Yep, Zaak, this is pretty in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957784#M93970</link>
    <description>&lt;P&gt;Yep, Zaak, this is pretty much exactly the only solution I had figured so far.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Mar 2014 17:27:14 GMT</pubDate>
    <dc:creator>Sergio</dc:creator>
    <dc:date>2014-03-26T17:27:14Z</dc:date>
    <item>
      <title>Override default component initialization</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957775#M93961</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I understand the following is not legal:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;
module foo
type :: bar
    integer :: a=53
end type

type, extends(bar) :: rab
    integer :: a=-33333 !!! Redefine default initialization
end type
end module&lt;/PRE&gt;

&lt;P&gt;I think this would be quite practical. The only workaround is implementing clumsy constructor wrappers...&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2014 10:24:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957775#M93961</guid>
      <dc:creator>Sergio</dc:creator>
      <dc:date>2014-03-24T10:24:38Z</dc:date>
    </item>
    <item>
      <title>I prefer not to use default</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957776#M93962</link>
      <description>&lt;P&gt;I prefer not to use default initialization; I&amp;nbsp;use constructors instead.&amp;nbsp; And the Fortran 2003 feature of being able to name&amp;nbsp;an interface block the same as the type name gives me options&amp;nbsp;to apply generics on&amp;nbsp;constructors that are sufficient and flexible enough for my needs.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2014 15:39:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957776#M93962</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-03-24T15:39:51Z</dc:date>
    </item>
    <item>
      <title>I also tend to use</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957777#M93963</link>
      <description>&lt;P&gt;I also tend to use constructors, but in this very particular case, the default constructors suit me perfectly. There are no additional components that I need to initialize by hand, etc. But sure, the initializer (using the interface to use the same name as the type as you said) is the one I had to implement so far...&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2014 16:50:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957777#M93963</guid>
      <dc:creator>Sergio</dc:creator>
      <dc:date>2014-03-24T16:50:34Z</dc:date>
    </item>
    <item>
      <title>What you propose looks like a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957778#M93964</link>
      <description>&lt;P&gt;What you propose looks like a duplicate component name declaration. I understand what you want to accomplish, but that's just not how the language tends to work. As you found, it is easy to write your own constructors.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2014 11:18:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957778#M93964</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-03-25T11:18:41Z</dc:date>
    </item>
    <item>
      <title>Hi Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957779#M93965</link>
      <description>&lt;P&gt;Hi Steve,&lt;/P&gt;

&lt;P&gt;But why would it be a problem? As long as the type of the component is identical to the parent one, redefining the default initialization should not break anything.&lt;/P&gt;

&lt;P&gt;Along these lines, I have another question. What is the correct way to set inherited private components? Let's suppose I have the following types:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;
module foo
    type, abstract :: Dad
        private
        integer :: i
    end type

    type, extends(Dad) :: Son
    end type
end module

program main
    use foo

    type(Son) :: guy

    guy=Son(i=3)      ! i is private
    guy%dad=Dad(i=3)  ! Dad cannot be "instantiated", it's abstract
end program&lt;/PRE&gt;

&lt;P&gt;...&lt;/P&gt;

&lt;P&gt;What is the correct way to set the component i of something variable? Are getters/accessors the only possibilities?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2014 11:33:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957779#M93965</guid>
      <dc:creator>Sergio</dc:creator>
      <dc:date>2014-03-25T11:33:18Z</dc:date>
    </item>
    <item>
      <title>Extended derived types (i.e.,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957780#M93966</link>
      <description>&lt;P&gt;Extended derived types (i.e., children class) have access to parent members, so you can add a "setter" method to your child class: say you create SUBROUTINE called SetI which takes an argument ValueOfI.&amp;nbsp; Your program can then&amp;nbsp;invoke this as CALL Son%SetI(ValueOfI=3).&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2014 12:08:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957780#M93966</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-03-25T12:08:38Z</dc:date>
    </item>
    <item>
      <title>Well, this is not 100% true.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957781#M93967</link>
      <description>&lt;P&gt;Well, this is not 100% true. Dad's private component is accessible if Son is defined in the same module. The following code does not compile:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;
module foo
    implicit none
    public :: Dad

    private
    type, abstract :: Dad
        private
        integer :: i
    end type
end module

module foo2
    use foo
    implicit none

    public :: Son

    private
    type, extends(Dad) :: Son
    contains
        procedure :: set_i
    end type

    interface Son
        module procedure :: Son_init
    end interface
contains
    subroutine set_i(self,i)
        class(Son), intent(inout) :: self
        integer                   :: i
        self%i=i
    end subroutine

    function Son_init(i) result(new)
        integer, intent(in) :: i
        type(Son)           :: new

        new%i=i
    end function
end module

program main
    use foo2
    implicit none

    type(Son) :: guy

    guy=Son(i=3)
end program&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2014 14:20:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957781#M93967</guid>
      <dc:creator>Sergio</dc:creator>
      <dc:date>2014-03-25T14:20:47Z</dc:date>
    </item>
    <item>
      <title>Yep, that's one of the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957782#M93968</link>
      <description>&lt;P&gt;Yep, that's one of the limitations of the current Fortran standard, including 2008.&amp;nbsp; So&amp;nbsp;you have to either apply PUBLIC attribute to component i in the ABSTRACT type or include both the parent and child in the same module.&lt;/P&gt;

&lt;P&gt;I end up picking one of these options depending on my needs.&amp;nbsp; I&amp;nbsp;usually create a concrete base type off the abstract in the parent module with "getter" and "setter" methods; child modules then extend the concrete type instead of the abstract.&lt;/P&gt;

&lt;P&gt;In one case, I ended up with several concrete types (analogy: abstract shape class; concrete bases for 2-D and 3-D; children: triangle, circle, etc. for 2-D and sphere, cylinder, pyramid, etc. for 3-D), abstract and concretes all in one (parent) module, but the children were in their own individual modules.&lt;/P&gt;

&lt;P&gt;And yes, this won't satisfy OOP-purists but one is constrained by the language features.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2014 14:48:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957782#M93968</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-03-25T14:48:58Z</dc:date>
    </item>
    <item>
      <title>I think the constructor</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957783#M93969</link>
      <description>&lt;P&gt;I think the constructor method is definitely the way to go here; a little bit more typing, but the client code can remain unchanged, so you don't have to repeat yourself:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;
module foo
  implicit none
&amp;nbsp; private
&amp;nbsp; public :: bar ,rab
&amp;nbsp; type :: bar
     private
     integer :: a=53
  end type
  type, extends(bar) :: rab
  end type
  interface rab
     procedure :: constructor
  end interface
contains
  function constructor(a) result(res)
&amp;nbsp;   integer ,optional ,intent(in) :: a
    type(rab)                     :: res
    res%a = -33333
&amp;nbsp;   if ( present(a) ) res%a = a
  end function
end module
&lt;/PRE&gt;

&lt;P&gt;If you want to allow the child and the parent to be contained in separate modules, you could create a type bound setter method for the abstract type (you could even make the input argument optional, and use a default if the input argument is omitted) then call the setter method from the constructor. One downside here, however, is that the setter method will now be publically exposed.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;
module foo
  implicit none
&amp;nbsp; private
&amp;nbsp; public :: bar
&amp;nbsp; type :: bar
     private
     integer :: a=53
   contains
     procedure :: a_setter
  end type
contains
  subroutine a_setter(this,a)
    class(bar)        ,intent(out) :: this
    integer ,optional ,intent(in)  :: a
    res%a = 53
    if ( present(a) ) this%a = a
  end subroutine
end module
module oof
  use foo
&amp;nbsp; implicit none
&amp;nbsp; private
&amp;nbsp; public :: rab
  type, extends(bar) :: rab
  end type
  interface rab
     procedure :: constructor
  end interface
contains
  function constructor(a) result(res)
    integer ,optional ,intent(in) :: a
    type(rab)                     :: res
    call res%a_setter(-33333)
    if ( present(a) ) call res%a_setter(a)
  end function
end module&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2014 17:21:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957783#M93969</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2014-03-26T17:21:00Z</dc:date>
    </item>
    <item>
      <title>Yep, Zaak, this is pretty</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957784#M93970</link>
      <description>&lt;P&gt;Yep, Zaak, this is pretty much exactly the only solution I had figured so far.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2014 17:27:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Override-default-component-initialization/m-p/957784#M93970</guid>
      <dc:creator>Sergio</dc:creator>
      <dc:date>2014-03-26T17:27:14Z</dc:date>
    </item>
  </channel>
</rss>

